Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如果表为空,cellForRowAtIndexPath应该返回什么?_Iphone_Objective C_Ios_Xcode_Uitableview - Fatal编程技术网

Iphone 如果表为空,cellForRowAtIndexPath应该返回什么?

Iphone 如果表为空,cellForRowAtIndexPath应该返回什么?,iphone,objective-c,ios,xcode,uitableview,Iphone,Objective C,Ios,Xcode,Uitableview,我想如果桌子是空的,也就是说 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 始终返回0 我希望根本不应该调用-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath 这很重要。我正在做一个程序来搜索东西,

我想如果桌子是空的,也就是说

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
始终返回0

我希望根本不应该调用
-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath

这很重要。我正在做一个程序来搜索东西,有时在搜索之后,没有返回结果


但是,无论如何都调用了,我得到了一个异常。我该怎么办?

返回1作为计数(例如10),并且一个单元格将显示暗显文本且“无结果”如何


(打开你的联系人应用程序并搜索一些内容。。它大约有10行,9行为空,1行显示“无结果”)

tableView:cellforrowatinexpath:
方法返回
0
时,根本不可能调用
tableView:numberofrowsinssection:
。很可能返回的计数不正确。

第一次打印
[[BNUtilities Quick GetBiz]计数];
NSLog
中的
,查看它是否真的返回0

如果它显示为0,并且如果仍然调用
cellforrowatinedexpath:
,我怀疑那里有鬼影。:-)


通常情况下,您会在cellForRow中有一个巨大的switch语句。。。这意味着您必须在默认情况下返回一个值。在那里我通常是零


编译器要求不显示警告,但不应实际调用它。此方法仅对由于重新返回numberOfSections和NumberRowsInSection方法而可能出现的行索引调用。

-tableview:cellForRowAtIndexPath:
可能在表视图意识到它没有行之前被调用,因此不应被调用


因此,您的实现需要检查传入的行的值是否在数组的边界之外。如果是,您需要返回一个空单元格(文档状态为返回
nil
将引发异常)。

最好将崩溃日志放在这里。检查
numberOfRowsInSection
中返回的内容,如果是0,则不调用
cellforrowatinexpath
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[BNUtilitiesQuick getBizs] count];
}