2014-01-28 68 views
0

我创建了一个XIB文件,然后创建一个类tableViewCell的。我附上了如何将插口连接到文件的照片。我试图将值赋给属于的tableview细胞创建过程中提出,但细胞不断出现空白,一旦应用程序运行的细胞。以下是我的代码和xib文件的一些截图。 任何帮助将大规模赞赏。自定义的UITableViewCell显示空白

+1

删除该行:'电池= [[LeagueCell的alloc]初始化]' – Desdenova

回答

2

您dequeing一个单元格,然后再次将其实例化。只是删除线的地方说:cell = [[LeagueCell alloc] init];

+0

惊人的,我傻,完美。谢谢!! –

0

删除线cell=[[LeagueCell alloc] init]; 和改变细胞的初始化如下:

cell = [[NSBundle mainBundle] loadNibNamed:@"LeagueCell" owner:self options:nil] objectAtIndex:0] 
0

尝试标签设置标签

UILabel *name = (UILabel *)[cell viewWithTag:100]; 
    UILabel *position = (UILabel *)[cell viewWithTag:101]; 
    UILabel *score = (UILabel *)[cell viewWithTag:102]; 

    cell.name = [currentObject valueForKey:@"username"]; 
    //rest of the code similarly 

也把

cell = [[LeagueCell alloc] init]; 

if (cell == nil) { 

    cell = [[LeagueCell alloc] init]; 

    } 
0

把这段代码被用于注册笔尖您在ViewDidLoad

UINib *nib = [UINib nibWithNibName:@"LeagueCell" bundle:nil]; 
[self.tableView registerNib:nib forCellReuseIdentifier:@"LeagueCellCellIdentifier"]; 

现在,CellForRowAtIndexPath

LeagueCell *pnCell = [tableView dequeueReusableCellWithIdentifier:@"LeagueCellCellIdentifier"]; 

return pnCell; 

注:CellForRowAtIndexPath使用相同CellIdentifier您在ViewDidLoad

0

给出 - (UITableViewCell的*)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath * )indexPath {

static NSString *[email protected]"cell"; 
League *cell=[tableView dequeueReusableCellWithIdentifier:cellidenfier]; 
if (cell==nil) { 
    cell=[[[NSBundle mainBundle]loadNibNamed:@"League" owner:self options:nil]objectAtIndex:0]; 
} 
return cell; 

}

请确保该文件所有者具有类NSObject的,你自定义单元格有类乌尔类名的。做一个出口从您的自定义类不能与fileowner ...

相关问题