iOS,覆盖cellForRowAtIndexPath以返回自定义单元格

4平方米

为了向可用于标识行的单元格添加属性,我创建了一个自定义单元格,该单元格是从UITableViewCell子类化的。该部分似乎工作正常,但是当我尝试实现didSelectRowAtIndexPath时,我无法获取自定义单元格指针,因此无法访问该属性。我是否需要覆盖cellForRowAtIndexPath?

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *MyIdentifier = @"MyReuseIdentifier";

    NLSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

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

    NSLog(@"indexPath: %ld", indexPath.row);
    NSDictionary *cellDict = [self.sql getTitleAndIdForRow:indexPath.row];

    NSArray *keys = [cellDict allKeys];
    id rowId = [keys objectAtIndex:0];
    id title = [cellDict objectForKey:rowId];

    cell.textLabel.text = title;
    cell.rowId = (NSUInteger)rowId;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    //This message returns a UITableViewCell, not a my custom NLSTableViewCell
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    NSString *string = [[NSString alloc] init];
    string = cell.textLabel.text;
    NSUInteger rowId = cell.rowId;
    NSLog(@"id: %ld, title: %@", rowId, string);
}
卑鄙的

铸造怎么样?

NLSTableViewCell *cell = (NLSTableViewCell *) [tableView cellForRowAtIndexPath:indexPath];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

删除按钮被自定义单元格覆盖

iOS-自定义表格单元格未达到UITableView的全宽

自定义MoreNavigationController的单元格

iOS-带自定义单元格的分组UITableView中的粘滞部分标题

iOS表格视图具有自定义子视图的单元格自动高度

具有ios中常见功能的自定义单元格

自定义tableview单元格在返回时未取消选择吗?

iOS拖放。拖动时如何用自定义视图替换单元格

dojo dgrid自定义渲染单元格内容

为什么自定义单元格为空白?

如何使用segue为Facebook iOS Friend Picker自定义背景和单元格?

iOS 7自定义单元格未在表格视图中显示

在iOS中使用自定义单元格时无法查看UITableViewCell

自定义单元格的UIView框架未在cellForRowAtIndexPath中更新

Swift iOS自定义单元格属性无法更改(解包空的可选)

iOS-如何实现自定义表格视图单元格的选择/取消选择?

自定义单元格标签

如何在iOS中管理自定义单元格标签值?

标签和Imageviews在iOS7中的自定义单元格中表现异常

IOS / Objective-C:在自定义单元格中制作圆形图像的代码

自定义单元格重复

Xamarin.iOS iOS 8 UITableView自定义单元格高度不变

iOS Swift自定义单元格NavigationController

iOS 10自定义单元格颜色Alpha被忽略

自定义文本框缩放-将文本返回到活动的datagridview单元格?

iOS UICollectionView初始化并更新自定义单元格

自定义类的表视图单元格返回nil

IOS/Objective-C:在自定义 Tableview 单元格中检测按钮按下?

自定义 tableview 单元格 xib 插座返回 nil