小编Dav*_*vid的帖子

在XCODE中使用我自己的Cell对象

我已成功创建了我的on"cell"对象(基于UITableViewCell),并在通过cellForRowAtIndexPath构建表时成功使用了它.

但是,如何在didSelectRowAtIndexPath中解构我所做的事情?

我目前收到错误"不兼容的指针类型初始化'MyCell*__ strong',表达式为'UITableViewCell'"

鉴于我的对象(MyCell)基于UITableViewCell,我不明白为什么我会收到此错误.

你能帮我理解我做错了吗?

我的另一种选择是对单元格中的两个标签中的每个标签使用"TAG"并以这种方式获得它们,但我只是在这里试验,试图了解更多关于这一切是如何工作的.

任何帮助将不胜感激.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"myCellID";
    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (cell == nil) {
        cell = [[MyCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:CellIdentifier];
    }

cell.accountCode.text = @"0009810";
cell.accountName.text = @"Agent Name";

return cell;
}
Run Code Online (Sandbox Code Playgroud)

这是另一种方法.我在MyCell遇到错误*cell = [tableView cellForRowAtIndexPath:indexPath];

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// Get the cell that was selected
MyCell *cell = [tableView cellForRowAtIndexPath:indexPath]; …
Run Code Online (Sandbox Code Playgroud)

xcode cell uitableview ios

4
推荐指数
1
解决办法
1771
查看次数

标签 统计

cell ×1

ios ×1

uitableview ×1

xcode ×1