Control may reach end of non-void function error if-statement

后端 未结 5 404
[愿得一人]
[愿得一人] 2021-01-20 06:48

I\'m getting the error Control may reach end of non-void function on this code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInte         


        
5条回答
  •  猫巷女王i
    2021-01-20 07:46

    Because when your all if condition fails, you are not returning anything from the function.

    Also multiple return statement in a function is not a good practice.

    Do it like:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        int count = 0;
        if (changeData.selectedSegmentIndex == 0)
        {
            count = self.tweets.count;
        }
        elset if (changeData.selectedSegmentIndex == 1)
        {
            count  = self.tweets1.count;
        }
        else if (changeData.selectedSegmentIndex == 2)
        {
            count  = self.tweets2.count;
        }
        return count;
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题