Sam Jarman
Sam Jarman

Reputation: 7377

getting error - 'control reaches end of non-void function'

Hey getting this error 'control reaches end of non-void function' on the line with the } on it. what am i doing wrong? please help

(NSString *)tableView:(UITableView *)tableView         titleForHeaderInSection:(NSInteger)section {
 NSLog(@"Here16");
 if (section == 0) {
  return @"A";
 }

 if (section == 1) {
  return @"B";
 }
 if (section == 2) {
  return @"C";
 }
 if (section == 3) {
  return @"D";
 }
 if (section == 4) {
  return @"E";
 }
 if (section == 5) {
  return @"F";
 }
 if (section == 6) {
  return @"G";
 }
 if (section == 7) {
  return @"H";
 }
 if (section == 8) {
  return @"I";
 }
 if (section == 9) {
  return @"J";
 }
 if (section == 10) {
  return @"K";
 }
 if (section == 11) {
  return @"L";
 }
 if (section == 12) {
  return @"M";
 }
 if (section == 13) {
  return @"N";
 }
 if (section == 14) {
  return @"O";
 }
 if (section == 15) {
  return @"P";
 }
 if (section == 16) {
  return @"Q";
 }

 if (section == 17) {
  return @"R";
 }
 if (section == 18) {
  return @"S";
 }
 if (section == 19) {
  return @"T";
 }
 if (section == 20) {
  return @"U";
 }
 if (section == 21) {
  return @"V";
 }
 if (section == 22) {
  return @"V";
 }
 if (section == 23) {
  return @"W";
 }
 //if (section==0) {
  //return @"X";
 //}
 if (section == 24) {
  return @"Y";
 }
 if (section == 25) {
  return @"Z";
 }

 //NSLog(@"%d", [listOfItems count]);



 NSLog(@"That whole error thing");
}

Upvotes: 2

Views: 5796

Answers (3)

Mark
Mark

Reputation: 21

Why not create a temp variable to hold the value you want to return, then return that variable?

NSMutableString *theString = [NSMutableString stringWithString:@" "];    
if (section == 0)     
{      
  [theString setString:@"A"]    
}    
else if(section == 1)    
{    
  [theString setString:@"B"]    
}

.....etc.....

return theString;

Note the use of Else If - in your existing code, every one of the conditions will be checked, which is very inefficient. If the first condition is met, none of the other conditions will be true, so using the Else If keeps the program for wasting time checking them.

Which basically tells me you need to go back and relearn some of the basics of programming.

Upvotes: 2

gcamp
gcamp

Reputation: 14662

If the letter you're getting is not in one of your choices, there will be no return. (It may never happen, but that's a warning…)

Try add return nil; at the end of you method

Upvotes: 3

amphetamachine
amphetamachine

Reputation: 30595

Try inserting something like:

return @"";

just before the end bracket.

The same thing might be achieved while looking prettier with something like a switch, though.

Upvotes: 1

Related Questions