简体   繁体   English

如何返回零自定义UITableViewCell

[英]How to return a nil custom UITableViewCell

In my cellForRowAtIndexPath method, it's fetching the data from the server. 在我的cellForRowAtIndexPath方法中,它是从服务器获取数据。 If one of the values of the data is false I want to change a few values of some global objects and skip implementing this cell, but when I try returning nil the app crashes. 如果数据值之一为false我想更改一些全局对象的一些值并跳过实现此单元格的操作,但是当我尝试返回nil ,应用程序崩溃。 I'm using Parse.com PFQueryTableViewController for the UITableViewController , so with the way things are set up it fetches all the data and then goes through it with calls the cellForRowAtIndexPath . 我正在为UITableViewController使用Parse.com PFQueryTableViewController ,因此通过设置方式,它会获取所有数据,然后通过调用cellForRowAtIndexPath I can't query objects that are true for said-value because when it's false , I need to change other things in my program. 我无法查询对于所述值正确的对象,因为当它为false ,我需要在程序中更改其他内容。

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7e30e400; frame = (0 95; 320 424); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x7b2a94b0>; layer = <CALayer: 0x7b2a8af0>; contentOffset: {0, 0}; contentSize: {320, 1690}>) failed to obtain a cell from its dataSource (<_UIFilteredDataSource: 0x7b26d5a0>)'

You can not return nil for cellForRowAtIndexPath which will crash your app. 您不能为cellForRowAtIndexPath返回nil,这会使您的应用程序崩溃。 You can just return a cell without any elements like: return [UITableViewCell new]; 您可以只返回一个不包含任何元素的单元格,例如: return [UITableViewCell new];

Well, in my opinion you'd better rearrange your datasource array, just pick the 'true' out into a new array. 好吧,我认为您最好重新排列数据源数组,只需将“ true”选出到新数组中即可。 Using the new array will fix your situation. 使用新阵列将解决您的情况。

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

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