UITableView 如何修改数据
来源:互联网 发布:好玩的网络竞技游戏 编辑:程序博客网 时间:2024/06/18 09:29
以下是截选出来一段 UITableViewController类
@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 = [tableViewdequeueReusableCellWithIdentifier:@"generic"];
if (!cell) cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"generic"];
// NSLog([NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]]);
cell.textLabel.text =@"Brightness";
cell.textLabel.textColor = [UIColorcolorWithWhite:(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]];
权当给我自己做注解了。。
- UITableView 如何修改数据
- 如何修改数据:update
- 如何修改UITableView中SectionTitle的背景色
- 如何结合CoreData给UITableView的section填充数据
- 使用UITableView是如何判断reloadData加载数据已经结束
- UITableView没数据时用户提示如何做?
- 如何修改表的数据??
- 如何修改一次代码就可以完成多种类型 cell 的 UITableView 增删修改顺序?
- 修改UITableView背景图片
- 修改UITableView背景图片
- iOS 修改UITableView separator
- 修改数据后返回UITableView界面,Cell已创建但是表格不及时更新
- UITableView不显示数据
- UITableView 滑动删除数据
- UITableView刷新数据reLoadData
- UITableView刷新数据
- UITableView 数据展示
- UITableView 数据展示 cell
- c++多线程(四)
- m_pclassinit不是afx_module_state的成员
- 北大ACM 2739 Sum of Consecutive Prime Numbers
- 逻辑回归
- C#算法学习-->递归
- UITableView 如何修改数据
- uva11354 - Bond
- cygwin使用过程中下的各种记录
- 我的android 第三天 - 自定义Toast
- 如何终止线程的运行(C/C++)
- SMO
- uva 11136 Hoax or what
- 适配器模式
- 微信公众平台开放 9 大高级接口,它有什么意义?