警告:控件到达非无效函数的末尾-iPhone

警告:控件到达非无效函数的末尾-iPhone,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我不断收到带有以下代码的“警告:控件到达非无效函数末尾”: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section ==0) { return [comparativeList count]; } if (section==1) { return [generalList count]; } if (section=

我不断收到带有以下代码的“警告:控件到达非无效函数末尾”:

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

 if (section ==0)

 {
  return [comparativeList count];
 }

 if (section==1) 
 {
  return [generalList count];
 }

 if (section==2)
 {

  return [contactList count];
我怎样才能摆脱这个警告


谢谢。

添加
返回0。如果不满足
条件,则基本上是故障保护

如果要确保满足其中一个条件,
return-1应导致应用程序引发异常和崩溃,这可能有助于跟踪错误

您还可以考虑修改此方法,并将
if
语句替换为
switch case
树。使用
开关盒
树,您可以非常轻松地添加新节,并在
UITableView
中重新排列它们的顺序。通过使用合理的命名约定,代码变得非常容易阅读

这真的很容易;弗雷泽·斯皮尔斯有一个好主意

一个选项:

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

    if (section ==0) {
        return [comparativeList count];
    } else if (section==1) {
        return [generalList count];
    }
    // section == 2    
    return [contactList count];
}

+1,OPs的实际警告很可能是“控制达到非无效函数的末尾”。是的,基本上任何表示将返回某些内容的方法或函数都应该返回某些内容。由于无法保证满足任何
条件,因此可能不会返回任何内容。非常感谢,它工作得很好,您的解释也非常有用。非常感谢您抽出时间:)