Warning: control reaches end of non-void function – iPhone

Add a return 0; at the end of your method. It’s basically a failsafe, if none of the if conditions are met.

If you want to make sure one of the conditions is met, return -1; should cause the application to throw an exception and crash, which might help you track down errors.

You might also look at modifying this method and replacing the if statements with a switch-case tree. With a switch-case tree, you can very easily add new sections and rearrange their order in a UITableView. The code becomes trivially easy to read by using sensible naming conventions.

It’s really easy; Fraser Speirs has a good explanation on how to set this up.

Leave a Comment