OGeek|极客世界-中国程序员成长平台

标题: ios - 填充表格 View 单元格 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 05:35
标题: ios - 填充表格 View 单元格

我目前有一个包含 2 个具有单独键的对象的字典,我想分别用每个对象填充一个表格 View 单元格。例如,比如说我的字典有 2 个对象,一个对象是北键,另一个对象是南键。现在我希望表格 View 有 2 个单元格,一个包含北,一个包含南。我该怎么做呢?到目前为止,我尝试了下面的代码,但这只会覆盖它。

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath{

    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier"Cell"];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier"Cell"];
    }

    NSMutableDictionary *news = (NSMutableDictionary *)[feeds objectAtIndex:indexPath.row];
    [cell.textLabel setText:[news objectForKey"frstDirection"]];
    [cell.textLabel setText:[news objectForKey"secDirection"]];

    return cell;
}



Best Answer-推荐答案


如果你确定你只有两个对象,你可以简单地使用这个:

NSMutableDictionary *news = (NSMutableDictionary *)[feeds objectAtIndex:indexPath.row];
if(indexPath.row==0){
     [cell.textLabel setText:[news objectForKey"frstDirection"]];
}else if(indexPath.row==1){
    [cell.textLabel setText:[news objectForKey"secDirection"]];
}

关于ios - 填充表格 View 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20315943/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4