I have three strings and each one either says True or False. Depending on which strings say True I would display them in the table view. Here is the code I have:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([appDelegate.showFirstField isEqualToString:@"True"]) {
if (indexPath.section==2) {
cell.textLabel.text=@"First Field Title";
}
}
if ([appDelegate.showSecondField isEqualToString:@"True"]) {
if (indexPath.section==3) {
cell.textLabel.text=@"Second Field Title";
}
}
if ([appDelegate.showThirdField isEqualToString:@"True"]) {
if (indexPath.section==4) {
cell.textLabel.text=@"Third Field Title";
}
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
int sectionNum = 2;
if ([appDelegate.showFirstField isEqualToString:@"True"]) {
sectionNum += 1;
}
if ([appDelegate.showSecondField isEqualToString:@"True"]) {
sectionNum += 1;
}
if ([appDelegate.showThirdField isEqualToString:@"True"]) {
sectionNum += 1;
}
return sectionNum;
}
The issue is that if showFirstField and showThirdField are True and showSecondField is False then the section title wont be set correctly. Is there a way I can set the title to the next available section.
After a couple hours working on it I took it from a different approach and this code works for me. set the
checkbooleans to false and as global variables