使用數組充填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"]];
}