Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ljg93

macrumors member
Original poster
Mar 13, 2011
98
0
the error i get is expected statement before else

Code:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
	if(section == 0)
		return @"Ways to contact us";
	else
		return @"Other Settings";
	else 
		return @"Our Website";


whats wrong?
 
Well, you have one if and two else, that doesn't work. Strangely enough that is exactly what the error tells you as well.

Did you intend something like this?
Code:
	if(section == 0)
		return @"Ways to contact us";
	else if(section == 1)
		return @"Other Settings";
	else 
		return @"Our Website";

You probably will want to check out the switch statement in that case anyway.
 
You have two else's in a row.

The condition evaluated by if is either true or false. There is no third outcome possible, so adding a second else is meaningless.

If you intend a series of if(x)/else if(y)/else, then you have to write it that way:
Code:
if ( some condition )
{  some result;  }
else if ( other condition )
{  other result;  }
else if ( yet another condition )
{  yet another result;  }
else
{  result when none of the other if/else's matched;  }
 
thanks guys that solved it! sorry im new at this! appreciate the help
 
You might want to look at switch. If/then is fine when you have a choice between two things. When there are multiple choices switch is easier to maintain:

Code:
switch section {
case 0: bar;
break;
case 1: foo;
break;
default:
foobar;
break;
}

- Olaf
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.