UITableView 如何修改数据
2013-11-10 22:37
260 查看
以下是截选出来一段 UITableViewController类
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
定义 Section块 数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
定义每个Section块中包含的行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"generic"];
if (!cell) cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"generic"];
// NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]);
cell.textLabel.text =
@"Brightness";
cell.textLabel.textColor = [UIColor
colorWithWhite:(indexPath.row /
10.0f) alpha:1.0f];
// cell.accessoryType = IS_IPAD ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
// NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]);
通过打印这句话。我们可以知道indexPath中存储的分别是 第几个Section 跟 第几个row
通过判断是哪个Section 跟哪个 row可以独立的修改 cell 的属性
cell.textLabel.text = NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];
权当给我自己做注解了。。
@interface ColorViewController : UITableViewController @end @implementation ColorViewController + (id) controller { ColorViewController *controller = [[ColorViewController alloc] init]; controller.title = @"Colors"; return controller; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"generic"]; if (!cell) cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"generic"]; // NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]); cell.textLabel.text = @"Brightness"; cell.textLabel.textColor = [UIColor colorWithWhite:(indexPath.row / 10.0f) alpha:1.0f]; // cell.accessoryType = IS_IPAD ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if (IS_IPAD) { UIViewController *controller = (UIViewController *)self.splitViewController.delegate; controller.view.backgroundColor = cell.textLabel.textColor; } else { DetailViewController *controller = [DetailViewController controller]; controller.view.backgroundColor = cell.textLabel.textColor; [self.navigationController pushViewController:controller animated:YES]; } } - (void) viewDidAppear: (BOOL) animated { self.tableView.rowHeight = 72.0f; } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return YES; } @end
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
定义 Section块 数量
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
定义每个Section块中包含的行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"generic"];
if (!cell) cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"generic"];
// NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]);
cell.textLabel.text =
@"Brightness";
cell.textLabel.textColor = [UIColor
colorWithWhite:(indexPath.row /
10.0f) alpha:1.0f];
// cell.accessoryType = IS_IPAD ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
// NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]);
通过打印这句话。我们可以知道indexPath中存储的分别是 第几个Section 跟 第几个row
通过判断是哪个Section 跟哪个 row可以独立的修改 cell 的属性
cell.textLabel.text = NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];
权当给我自己做注解了。。
相关文章推荐
- iOS之UITableView如何优雅的插入数据: 旋转180°下拉加载cell顶置
- UITableView没数据时用户提示如何做?
- IOS中使用UITableView的group时,如何让第一行数据挨着顶部
- 如何结合CoreData给UITableView的section填充数据
- iphone开发之表格组件UITableView的使用(二)如何分组展示数据并添加组头和组尾描述
- UITableView,UICollectionView和CoreData完美结合进行增删改操作,如何导入大量数据,如何利用NSEntityMigrationPol
- 如何修改一次代码就可以完成多种类型 cell 的 UITableView 增删修改顺序?
- 如何修改UITableView中SectionTitle的背景色
- 如何修改skype数据文件(聊天记录)的路径
- 如何修改数据:update
- UITableView如何开启极简模式
- Oracle如何修改字段数据类型(转)
- ios tableView那些事 (十八) UITableView单行刷新数据
- IOS UItableView得group风格如何去掉分割线问题
- iOS开发笔记--如何去掉UItableview header(footer)view黏性(sticky)
- 读书笔记5——如何改变已修改列的颜色,提示用户该数据已修改
- PB如何在Datawindow(数据窗口)中控制列的修改方式
- 如何写好一个UITableView(上)
- 一种让UITableView的数据从下往上增长的方式
- 创建操作/删除多行数据的UITableView的细节