2014-01-23 54 views
0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"GenusNameCell"; 

    GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"]; 


     cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 

    } 

    return cell; 
} 

我有一个tableview与一个对象的数组,但是当我运行它。什么都没有出现。我相当新的Xcode,但林不知道我的错误是在代码中。有人可以帮我吗?表视图不填充对象

+0

你初始化您的数组'genusName'? – AncAinu

+0

GenusNameCell:从xib? – Larme

+0

代码看起来不错。数据一定不好。请确认。 – trojanfoe

回答

0

变化这样你的代码的代码将运行,

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

static NSString *CellIdentifier = @"GenusNameCell"; 

GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"]; 

    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 

} 
cell.GenusNameLabel.text = [[genusName objectAtIndex:indexPath.row] geniusname]; 

return cell; 
} 

geniusname是NSString的你保存的人的名字。

+0

这并没有做 – user3228210

+0

你怎么能保存你的字符串在数组上,..你能分享你的代码请 –

+0

其实,你将所有的数据添加到一个genusName数组..然后只有你可以从中检索,.. –

1

如果回调的cellForRowAtIndexPath从不调用,则可能是:

  • 你没有设置你的tableview的数据源;
  • 您没有实现numberOfSectionsInTableView:和/或tableView:numberOfRowsInSection:callbacks。

如果你离队你的,你需要设置文本之外的,如果这样的分支:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"GenusNameCell"; 

    GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"GenusNameCell"]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 
    } 
    cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row]; 

    return cell; 
} 
+0

谢谢你的工作 – user3228210