tags:

views:

397

answers:

3

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");
}
+2  A: 

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.

amphetamachine
that gives me this in the crash log2010-01-07 18:15:19.036 FlagLearner[13310:207] *** -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x38145302010-01-07 18:15:19.039 FlagLearner[13310:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x3814530'2010-01-07 18:15:19.047 FlagLearner[13310:207] Stack:( [stack removed for comment space] )
Sam Jarman
whats a switch?
Sam Jarman
A switch is a statement of the following form:switch(integerVar){ case 1: NSLog(@"1"); break;case 2: NSLog(@"2"); break;default: NSLog(@"We got all the way down to default!");}
Elise van Looij
+2  A: 

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

gcamp
that gives me this in the crash log2010-01-07 18:15:19.036 FlagLearner[13310:207] *** -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x38145302010-01-07 18:15:19.039 FlagLearner[13310:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString objectForKey:]: unrecognized selector sent to instance 0x3814530'2010-01-07 18:15:19.047 FlagLearner[13310:207] Stack:( [stack removed for comment space] )
Sam Jarman
There's no error on the code in your question, the error is somewhere else...
gcamp
email me at [email protected] for the source code.. i'd like you to take a look at it please!
Sam Jarman
+1  A: 

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.

Mark
+1 for "relearn some of the basics of programming". I can think of at least one or two more efficient methods of doing this (either through simple arithmetic, or if the sdk doesn't provide this, through a conversion table)
Kena