开发者社区> 问答> 正文

使用 NSMutableArray充填UItableview

使用数组充填UItableview ,需要在数组的cell中匹配对象。

数组如下:

(
        (
                {
            cost = 160;
            height = 1;
            room_number = 1;
            square_size = 1;
            title = "TIMBER BLINDS";
            width = 1;
        }
    ),
        (
                {
            cost = 170;
            height = 1;
            room_number = 2;
            square_size = 1;
            title = "ROMAN BLINDS";
            width = 1;
        }
    )

问题:怎么将正确的标题匹配到cell中,配对条件是array的room_number。

展开
收起
爵霸 2016-03-17 11:13:58 2078 0
1 条回答
写回答
取消 提交回答
  • 你用数组的数组,其中包含了dictionary,因此第一步需要用indexPath.row从数组中获取对象。获取的对象也是一个数组,再用objectAtIndex从中获取字典对象。这样你就可以获取字典也就可以访问键值了。

    NSMutableArray *fetchedArray= [yourArray objectAtIndex:indexPath.row];
    NSDictionary *fetchedDictionary = [fetchedArray objectAtIndex:0];
    
    NSNumber *roomNumber= [fetchedDictionary valueForKey:@"room_number"];
    if([roomNumber intValue] == indexPath.row) {
        [cell setTextLabel:[fetchedDictionary valueForKey:@"title"]];
    }
    2019-07-17 19:04:54
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载