我目前正在开发一个应用程序,使用NSArrays中的数据显示足球比赛中的比赛安排。我现在想将数据放入部分,例如,第一轮显示3场比赛,第二轮显示6场比赛,等等。
有没有人可以帮助我如何在UITable中按部分显示数据?
致敬约翰
发布于 2011-03-17 16:40:12
为此,我通常在NSArray中使用NSArrays。
下面是我创建数据源数组的方式:
NSArray *section0 = [NSArray arrayWithObjects:@"Section 0 Row 0", @"Section 0 Row 1", nil];
NSArray *section1 = [NSArray arrayWithObjects:@"Section 1 Row 0", @"Section 1 Row 1", @"Section 1 Row 2", nil];
self.tableViewData = [NSArray arrayWithObjects:section0, section1, nil];和一些UITableView方法,这样你就明白了:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.tableViewData count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.tableViewData objectAtIndex:section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyObject *object = [[self.tableViewData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
// Do something
} 对于部分的标题(和索引),我创建了单独的NSArrays。
发布于 2011-03-17 16:37:46
最好创建Array of Array。假设你有3个部分,每个部分有4行。因此,使用三个数组对象.and创建一个数组,每个内部数组都将包含rows值
发布于 2011-03-17 16:38:54
您需要创建一个符合的类。这个类通常是UIViewController的子类。然后,应将UITableView的dataSource属性设置为指向此类的实例。您的数据源类应该实现协议中的方法,以便它根据模型中的数据返回值(因此这是一个控制器类)。如果有帮助,您还可以使用UIViewController子类UITableViewController。
https://stackoverflow.com/questions/5336651
复制相似问题