简体   繁体   English

iPhone:重新加载tableview行时崩溃

[英]iPhone: Crash when reloading a tableview row

I'm using the following section of code - it should be simple, but it's causing me a lot of trouble: 我正在使用以下代码部分-它应该很简单,但是却给我带来很多麻烦:

NSUInteger index[] = {1,0};   // top row of section one
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath     
indexPathWithIndexes:index length:2]] withRowAnimation:UITableViewRowAnimationNone];

The code crashes on the second line, with the error that "The number of rows in section zero is not equal to the number of rows in section zero before the update". 代码在第二行崩溃,错误为“更新前零节中的行数不等于零节中的行数”。

This error is true, I'm changing the number of rows in section zero. 这个错误是正确的,我正在更改零节中的行数。 But surely this shouldn't effect whether or not I can reload a row in section 1!? 但这肯定不会影响我是否可以在第1节中重新加载行!

- --

Am I misunderstanding how something works, or is something else going wrong somewhere? 我是在误解某事是如何工作的,还是在某处出现了其他问题? Any help or ideas are much appreciated :) 任何帮助或想法都非常感激:)

I think you also need to update the numberOfRowsInSection . 我认为您还需要更新numberOfRowsInSection

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return rowCount;
}

If you are changing (reloading) the number of rows in section 0 (probably by deleting or adding some rows in it) then - 如果要更改(重新加载)第0节中的行数(可能是通过删除或添加其中的一些行),则-

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)节

is called to get the new number of rows. 被调用以获取新的行数。 Here you need to return the correct number of rows ie one row less, if you deleted a row in section zero. 如果您在第0节中删除了一行,则需要返回正确的行数,即少一行。

So basically, if you were returning [someArray count] for number of rows in section 0, you need to update this someArray as well. 因此,基本上,如果要返回第0节中的行数[someArray count],则也需要更新此someArray。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM