.h文件@property (nonatomic,strong)UITableView *tableView;.m文件//viewDidLoad 的代码- (void)viewDidLoad { [super viewDidLoad]; //创建一个tableView并使用自己写的delegate self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; self.tableView.delegate
= self; self.tableView.dataSource = self; [self.view addSubview:self.tableView]; }#pragma mark 重写delegate的两个方法-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 10;}-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = nil; static NSString *cellIdentifier = @"cells"; cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:cellIdentifier]; //cell.textLabel.text = [NSString stringWithFormat:@"Section %ld Cell %ld", // (long)indexPath.section , (long)indexPath.row]; cell.textLabel.text = @"hello"; return cell;}
IOS 开发之UITableview的基本创建
最新推荐文章于 2025-12-04 16:09:55 发布
本文详细介绍如何在iOS应用中使用UITableView组件。从初始化TableView到实现数据源及代理方法,包括加载单元格、设置单元格内容等步骤都有详尽的说明。
941

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



