Xib的两种加载方式,与xib建立关系的两种方式

来源:互联网 发布:fpga经典书籍 知乎 编辑:程序博客网 时间:2024/05/18 06:23

@implementation JRTableViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    self.tableView.rowHeight =90;

}


#pragma mark - Table view data source


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

   return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

   return 100;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    staticNSString * ID =@"JRCell";//这个ID要和xib设定的indentifier一致

    JRTableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:ID ];

   if (!cell) {

//        方式一,加载nib

        NSArray * array = [[NSBundlemainBundle]loadNibNamed:@"JRCell"owner:niloptions:nil];

        cell = [arrayfirstObject];

        

//        方式二,加载nib

//        UINib * nib = [UINib nibWithNibName:@"JRCell" bundle:nil];

//        NSArray * array = [nib instantiateWithOwner:nil  options:nil];

//        cell = [array firstObject];

    

    }

    

//    方法一,通过tag

//    UIImageView * imageview = (UIImageView *)[cell viewWithTag:101];

//    NSString * icon = [NSString stringWithFormat:@"head%i", arc4random_uniform(8)+1];

//    imageview.image = [UIImage imageNamed:icon];

    

    //   方法二,建类,连线(连线之前一定要更改xibclass

    NSString * icon = [NSStringstringWithFormat:@"head%i",arc4random_uniform(8)+1];

    cell.icon.image = [UIImageimageNamed:icon];

    

   return cell;

    

}


0 0
原创粉丝点击