Ale*_*iop 16 objective-c uitableview
我已经尝试搜索一些关于如何填充表视图的教程,但我发现的只是旧的和过时的视频.我尝试从稍微更新的那个做,但它不起作用.我有
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[chemarray addObject:@"2"];
[chemarray addObject:@"test"];
[chemarray addObject:@"3"];
[chemarray addObject:@"science"];
}
Run Code Online (Sandbox Code Playgroud)
和
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [chemarray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = [chemarray objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
根据本教程,在运行时,它应该显示我的数组中的项目,但对我来说,它不会!有谁知道如何解决这一问题?
rck*_*nes 24
您忘记为单元标识符注册 nib/class.
形成Apple UITableView文档:
要点:在调用方法之前,必须使用
registerNib:forCellReuseIdentifier:orregisterClass:forCellReuseIdentifier:方法注册类或nib文件dequeueReusableCellWithIdentifier:forIndexPath:.
这是一个简单的例子UITableViewCell:
- (void) viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
}
Run Code Online (Sandbox Code Playgroud)
如果您没有注册nib/class,则该方法dequeueReusableCellWithIdentifier:forIndexPath:基本上与dequeueReusableCellWithIdentifier:.并且它不会自动为您创建实例.
| 归档时间: |
|
| 查看次数: |
18561 次 |
| 最近记录: |