Я использую tableView с настраиваемыми заголовками разделов. Все работает так, как ожидалось, но порядок разделов не отвечает, как я ожидал. Это словарные данные, которые я использую. В моей желаемой последовательности я хочу, чтобы «предстоящий» был как 1-й, так и «Посещался» как 2-й раздел, но порядок, который он показывает, полностью противоположный этому.UITableView разделы не работают
tableSection = @{@"Upcoming" : @[@"Amit", @"Vatsala", @"Jasmine", @"Jasmine", @"Jasmine"],
@"Attended" : @[@"Kritarth", @"Rahul"] };
Прошу предложить помощь!
#pragma mark - UITableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [tableSection count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 150;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection: (NSInteger)section {
return 25;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [tableSectionTitles objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
NSString *sectionTitle = [tableSectionTitles objectAtIndex:section];
NSArray *sectionAnimals = [tableSection objectForKey:sectionTitle];
return [sectionAnimals count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableCell";
AppointmentTableCell *cell = (AppointmentTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"AppointmentTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//Configure the cell...
NSString *sectionTitle = [tableSectionTitles objectAtIndex:indexPath.section];
NSArray *sectionArray = [tableSection objectForKey:sectionTitle];
cell.nameLabel.text = [sectionArray objectAtIndex:indexPath.row];
cell.doctorImageView.image = [UIImage imageNamed:@"doctor.png"];
[cell.nameLabel setFont:FONT_OPENSANS_LIGHT(14)];
return cell;
}
Можете ли вы показать нам какой-нибудь код? Все ваши методы tableView-delegate были бы хорошим началом. – TMob
Я попробовал тот же код после удаления массива. Тем не менее он дает мне тот же порядок разделов. – Arti
Извините, что я удалил свой комментарий и просто дал ему ответ. Был ли заказ tableSectionTitles в том порядке, в котором вы хотели? Это должно быть просто вопросом того, чтобы быть в правильном порядке, а остальное должно было встать на свои места. –