我有一个名为dummyData的数组数组,我在将数组注释中的计数作为表格中的行数返回时遇到问题。
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *commentsArray=[[dummyData objectAtIndex:section] valueForKeyPath:@"comments"];
NSLog(@"Comments: %d", [commentsArray count]);
if (section == didSection) {
return [[[dummyData objectAtIndex:section] valueForKeyPath:@"comments"] count];
}
return 0;
}
它给了我这个错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第0节中的行数无效。更新后的现有部分中包含的行数(3)必须等于行数在更新(0)之前包含在该部分中,加上或减去从该部分插入或删除的行数(插入2个,删除0个)以及加入或减去移入或移出该部分的行数(0移入,0搬出去。'
这是我的阵列:
dummyData = [[NSMutableArray alloc] init];
[dummyData addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", @"badge.png",@"Got Strike! at", @"Alex Shin",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"James", @"30 minutes ago", @"Great Shot!", @"https://c676132.ssl.cf0.rackcdn.com/_84A2468-50cf361795eb2.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Kim", @"10 minutes ago", @"I should have seen it.", @"http://3.bp.blogspot.com/-tBFQC9y-ZpM/Tmb8DaeYEmI/AAAAAAAAA9M/TahVx2IiQsE/s400/Bowling+and+Best+Bowling+Player+Shalin+Zulkifli+cover.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Matt", @"5 minutes ago", @"Nice", @"http://www.beverlyhillsmagazine.com/wp-content/uploads/Ashton-Kutcher-Hollywood-Stars-Rich-and-Famous-Movie-Stars-Star-of-the-Week-Beverly-Hills-Magazine-Hollywood-Magazines--300x336.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]]
, nil] , nil]
forKeys:[NSArray arrayWithObjects:@"photo", @"credit",@"credit_label", @"name", @"comments", nil]
]];
[dummyData addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", @"location_icon.png",@"Checked in at", @"Jessah Ouano",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Matt", @"1 hour ago", @"Welcome!", @"http://www.beverlyhillsmagazine.com/wp-content/uploads/Ashton-Kutcher-Hollywood-Stars-Rich-and-Famous-Movie-Stars-Star-of-the-Week-Beverly-Hills-Magazine-Hollywood-Magazines--300x336.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Steve", @"47 minutes ago", @"You'll enjoy here.", @"http://www.oozyleaks.com/wp-content/uploads/2013/09/Taylor-Lautner.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]]
, nil] , nil]
forKeys:[NSArray arrayWithObjects:@"photo", @"credit",@"credit_label", @"name", @"comments", nil]
]];
[dummyData addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", @"location_icon.png",@"Checked in at", @"Richard Son",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Pinky", @"3 hours ago", @"I saw it", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Tom", @"1 hour ago", @"realy?", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Caty", @"11 minutes ago", @"yes", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]]
, nil] , nil]
forKeys:[NSArray arrayWithObjects:@"photo", @"credit",@"credit_label", @"name", @"comments", nil]
]];
[dummyData addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", @"badge.png",@"Got a Strike! at", @"Dexter Dulay",
[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Matt", @"12 minutes ago", @"Take the opportunity", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Dex", @"11 minutes ago", @"Maybe later", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Drew", @"9 minutes ago", @"Alex should win", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Alex", @"9 minutes ago", @"As always. :)", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]],
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:@"Luis", @"2 minutes ago", @":D", @"http://g-ecx.images-amazon.com/images/G/01/electronics/detail-page/Klipsch-Image-S4-II-Black-Lifestyle.jpg", nil]
forKeys:
[NSArray arrayWithObjects:@"name", @"dateline", @"body", @"image_url", nil]]
, nil] , nil]
forKeys:[NSArray arrayWithObjects:@"photo", @"credit",@"credit_label", @"name", @"comments", nil]
]];
我的问题是,如何返回每个部分的评论数量。因为评论数组有不同数量的内容或计数。
答案 0 :(得分:1)
修正了问题:
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSArray *commentsArray=[[dummyData objectAtIndex:section] valueForKeyPath:@"comments"];
NSLog(@"Comments: %d", [commentsArray count]);
if (section == didSection) {
return [[[dummyData objectAtIndex:section] valueForKeyPath:@"comments"] count];
}
return 0;
}