使用自定义的tableViewCell- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS

来源:互联网 发布:diffrac.eva软件下载 编辑:程序博客网 时间:2024/04/30 08:31

新建一个类ContactCell,继承自UITableViewCell。新建一个xib文件(ContactCell.xib),视图为selfCell类。




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法中使用自定义的cell。

static NSString *CellIdentifier = @"Cell";

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

   BOOL registered = NO;

   if(!registered){

    [tableView registerNib:nib forCellReuseIdentifier:@"Cell"];

    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    registered = YES;

}


或者

    ContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {

        cell = [[ContactCell allocinitWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    }

    


0 0