开发者社区 问答 正文

使用 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 2149 分享 版权
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
    赞同 展开评论
问答地址: