使用数组充填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。
你用数组的数组,其中包含了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"]];
}