What is wrong with the following statements?
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *title;
switch (section)
{
case 0:
title = @"Section 1";
break;
case 1:
title = @"Section 2";
break;
default:
break;
}
return title;
}
Why do I get the logic error “Undefined or garbage value returned to caller” on analyzing this code?
set NSString * title to nil:
NSString * title = nil;if(section is neither 0 nor 1 ) then switch (section) goes through default: and then it return title; which is just pointer pointing to nothing or uninitialized.
So assign title string to nil; where you declared it.