Я создал сгруппированное представление таблицы. У меня есть 3 раздела, и я пытаюсь отобразить разные строки для всех разделов, используя 1 массив. но он отображает один и тот же текст ячейки для всех разделов. здесь представлены методы делегатов, которые я реализовал.сгруппированный табличный просмотр с одинаковыми значениями строк для разных разделов
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
mSectionArray = [NSArray arrayWithObjects:@"abc", @"def",@"ghi", nil] ;
return [mSectionArray count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0) {
mContentArray = [NSArray arrayWithObjects:@"hello",@"hello1", nil];
}
if(section == 1) {
mContentArray = [NSArray arrayWithObjects:@"one", @"two",@"three",@"four",@"five", nil];
NSLog(@"section 1 %@",mContentArray);
}if (section == 2){
mContentArray = [NSArray arrayWithObjects:@"abc", nil];
}
return [mContentArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSString *sectionHeader = nil;
if(section == 0) {
sectionHeader = @"abc";
}
if(section == 1) {
sectionHeader = @"def";
}
if (section == 2) {
sectionHeader = @"ghi";
}
return sectionHeader;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
}
cell.textLabel.text = [mContentArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor darkGrayColor];
return cell;
}
Он показывает «один» «два» «три» и т. Д. Во всех разделах, но мне нужны разные значения для разных разделов. помогите мне в решении проблемы.
примечания стороны - пожалуйста, узнать о 'if-else' заявлении. – rmaddy
@Newbee проверить мой обновленный ответ. Он разрешил сбой –