.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的基本创建
最新推荐文章于 2024-09-26 15:35:56 发布