我有一个UITableView
,我在其中列出了以下代码。
如何对这些对象进行分区,如下所示?
的数学
代数
几何
演算
科学
综合1
综合2
以下是代码:
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Math",@"Science",@"English",@"Social Studies",@"Spanish",@"German",@"French",@"Biology",nil];
self.listData = array;
[array release];
[super viewDidLoad];
}
答案 0 :(得分:0)
您必须使用分区表视图,这是实现此目的的最佳方法。您可以参考以下教程 - http://www.xcode-tutorials.com/uitableview- - 3-sectioned-table-view /
答案 1 :(得分:0)
在UITableView对象的UITableViewDataSource中;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return array.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [array objectAtIndex:section];
}
将根据您的情况执行“切片”部分。
答案 2 :(得分:0)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [yourarray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [yourarray objectAtIndex:section];
}