2013-04-04 66 views
0

我想在UITableView中添加数据源。我尝试以下,但遗憾的是它没有工作:UITableView和数据源

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 8; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    // Set the data for this cell: 

    cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text = @"One"; 
    cell.detailTextLabel.text = @"Two"; 



    // set the accessory view: 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    return cell; 
} 
+0

是否调用了cellForRowAtIndexPath? – SG1 2013-04-04 21:08:26

+1

你是什么意思的“没有工作”? – tilo 2013-04-04 21:08:49

+0

我看不到'tableView:numberOfRowsInSection:'的实现,'UITableViewDataSource'是必需的。你可以张贴吗? – MishieMoo 2013-04-04 21:13:59

回答

0

cell.textLabel.text = [_classCellview objectAtIndex:indexPath.row];

你告诉表有8个部分,但你不采取从section填充单元格时考虑的索引路径。索引路径具有(在表格视图的情况下)两个值:一个section和一个row。你需要他们都知道你在处理什么细胞。所以,你可能会得到相同的内容在你的表的每个部分重复。 (但是,如果你告诉我们究竟是什么问题,它会有所帮助。)

+0

我有表格显示,但我想标签字段“一”和“两个”显示在表内。 – 2013-04-04 22:40:29

+0

在这种情况下,看看你在用细胞的细节标签做什么。您将'@“一个”''分配给它的'text'属性,然后在下一行分配'@“两个”''到同一个标签。一个标签一次只能有一个值 - 如果您想要“一个两个”,您应该首先组合字符串并将结果分配给标签。 – Caleb 2013-04-05 02:00:29

相关问题