@interface RootViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> |
|
|
@property (nonatomic, strong) NSArray *timeZoneNames; |
@end |
重写UITableViewController对象的loadView方法,把UITableView增加到UITableViewController的视图中进行管理
- (void)loadView |
{
|
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; |
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; |
tableView.delegate = self; |
tableView.dataSource = self; |
[tableView reloadData]; |
|
|
self.view = tableView; |
} |
[tableView reloadData]把已经设置过的数据,更新显示到视图中去
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {//UITableView中有几部分
|
return [regions count]; |
} |
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {//UITableView的部分中有几行
|
// Number of rows is the number of time zones in the region for the specified section. |
Region *region = [regions objectAtIndex:section]; |
return [region.timeZoneWrappers count]; |
} |
|
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {//UITableView中指定部分的头部标题
|
// The header for the section is the region name -- get this from the region at the section index. |
Region *region = [regions objectAtIndex:section]; |
return [region name]; |
} |
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//设置cell与数据绑定
|
static NSString *MyIdentifier = @"MyReuseIdentifier"; |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; |
if (cell == nil) {
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; |
} |
Region *region = [regions objectAtIndex:indexPath.section]; |
TimeZoneWrapper *timeZoneWrapper = [region.timeZoneWrappers objectAtIndex:indexPath.row]; |
cell.textLabel.text = timeZoneWrapper.localeName; |
return cell; |
} |
本文详细介绍了如何在iOS应用中管理UITableView对象,包括加载视图、配置数据源和分段标题,以及展示时间区数据。通过实现loadView方法、设置UITableView属性、重写相关方法来实现数据的动态更新和展示。

被折叠的 条评论
为什么被折叠?



