我已到處尋找這個,但我無法找到確切的答案......都有輕微的變化。嵌套到UITableView的NSArray
無論如何,我叫一個JSON頁面返回以下(從的NSLog):
{
messages = {
1 = {
Body = "This is the body of message 1";
Title = "Message 1";
};
2 = {
Body = "This is the body of message 2";
Title = "Message 2";
};
};
}
我然後將數據保存到一個NSDictionary中(稱爲messageArray)。 (數組被一個NSMutableArray的)
然後我做的:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
//put rowsarray into dictionary
NSDictionary *dictionary = [messageArray objectAtIndex:indexPath.section];
//new dictionary into array
NSArray *messages = [dictionary objectForKey:@"messages"];
NSLog(@"the message array = %@",messages);
//this fails
cell.textLabel.text = [messages objectAtIndex:indexPath.row];
return cell;
返回的NSLog(所以我假設我的JSON陣列工作正常):
the message array = {
1 = {
Body = "This is the body of message 1";
Title = "Message 1";
};
2 = {
Body = "This is the body of message 2";
Title = "Message 2";
};
}
我明白,我沒有正確標記textlabels.text,但我不知道如何去循環「消息」數組,顯示數組中的所有「標題」值,以顯示在我的用戶界面上TableView列表。
我確定我錯過了這麼簡單的事情......但它直到現在都沒有了。任何鏈接歡迎...我將繼續尋找自己....
我已經加入此行:的NSLog(@ 「%@」,[消息objectAtIndex:indexPath.row]),和沒有愛。我得到無法識別的選擇器發送到實例。 – btwong 2010-12-14 03:14:33
嘗試記錄[消息類] – MCannon 2010-12-14 22:02:30