【发布时间】:2015-02-05 11:40:54
【问题描述】:
我正在使用带有自定义部分标题的 tableView。一切都按预期工作,但各部分的顺序没有像我预期的那样响应。这是我正在使用的字典数据。在我想要的序列中,我希望将“即将到来”作为第一部分,将“参加”作为第二部分,但它显示的顺序与此完全相反。
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 方法都是一个好的开始
-
我在删除数组后尝试了相同的代码。它仍然给了我相同的部分顺序。
-
对不起,我删除了我的评论,只是把它作为一个答案。 tableSectionTitles 的顺序是否符合您的要求?这应该只是确保它的顺序正确,其余的应该已经到位。
-
NSArray *sectionArray = [tableSection objectForKey:sectionTitle];字典没有定义的顺序。 -
我知道。但是我仍然面临这个问题,这就是我在这里发布这个的原因。
标签: objective-c xcode uitableview ios7