gpt4 book ai didi

ios - NSInternalInconsistencyException 原因 : 'Invalid update: invalid number of rows in section 0'

转载 作者:行者123 更新时间:2023-11-29 12:43:03 26 4
gpt4 key购买 nike

我有一个名为 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]
]];

我的问题是,如何返回每个部分的评论数。因为评论数组有不同数量的内容或计数。

最佳答案

解决了问题:

-(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;

关于ios - NSInternalInconsistencyException 原因 : 'Invalid update: invalid number of rows in section 0' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24401323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com