私は3つの文字列を持っており、それぞれがTrueまたはFalseを示しています。どの文字列がTrueであるかに応じて、テーブルビューに表示します。これが私が持っているコードです:
-(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;
}
問題は、showFirstField
とshowThirdField
がTrueでshowSecondField
Falseの場合、セクションタイトルが正しく設定されないことです。タイトルを次の利用可能なセクションに設定する方法はありますか?