ios - 未调用自定义 UITableViewCell didSelectRowAtIndexPath

标签 ios objective-c uitableview uiscrollview

我已经创建了一个自定义的 UITableViewCell 类,我用它来绘制我的 UITableViewCell。一切都正确绘制,但是由于我放入 UITableViewCell 的元素,我在选择单元格时遇到了问题。

这是我用来绘制 UITableViewCell 的方法,它是我的自定义 UITableViewCell

- (void)drawCell
{
    nameString = [[UILabel alloc] init];
    nameString.backgroundColor = [UIColor redColor];
    nameString.frame = CGRectMake(15.0, 0.5, 70.0, 40.0);
    nameString.text = [itemsDictionary objectForKey:@"Name"];

    lastNameString = [[UILabel alloc] init];
    lastNameString.backgroundColor = [UIColor clearColor];
    lastNameString.frame = CGRectMake(105.0, 0.5, 95.0, 40.0);
    lastNameString.text = [itemsDictionary objectForKey:@"LastName"];

    addressString = [[UILabel alloc] init];
    addressString.backgroundColor = [UIColor clearColor];
    addressString.frame = CGRectMake(220.0, 10.5, addressString.frame.size.width, 50.0);
    addressString.text = [NSString stringWithFormat:@"ISN %@: %@",[itemsDictionary objectForKey:@"AddNumber"] ,[itemsDictionary objectForKey:@"AddString"]];
    [addressString sizeToFit];

// scrollcell has a dynamic scrollwidth depending on the sddressString but has a framesize of a normal UITableViewCell
    scrollCell = [[UIScrollView alloc] init];
    scrollCell.backgroundColor = [UIColor blueColor];
    scrollCell.frame = CGRectMake(0.0, 0.0, ScreenWidth, 45.0);
    [scrollCell setContentSize:(CGSizeMake((220.0 + addressString.frame.size.width)+15, 45.0))];

    [scrollCell addSubview:nameString];
    [scrollCell addSubview:lastNameString];
    [scrollCell addSubview:addressString];
    [[self contentView] addSubview:scrollCell];
}

如您所见,我正在添加一个覆盖整个单元格的 UIScrollView,我认为这会阻止 UITableViewCell 委托(delegate)选择方法。

如何让委托(delegate)方法 didSelectRowAtIndexPath 工作?

最佳答案

您是否添加了以下内容?

@implementation ViewController <UITableViewDelegate, UITableViewDataSource>

并将代理设置为自己?

self.tableview.delegate = self;

关于ios - 未调用自定义 UITableViewCell didSelectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22546532/

相关文章:

objective-c - NSPredicate 过滤掉另一个集合中的所有项目

ios - 表/ Collection View 的水平滚动

ios - 如果对象的键不同,如何编写模型结构

iphone - iOS RestKit [mappingProvider setMapping :forKeyPath:] method? 的目的是什么

ios - objc_exception_throw/崩溃/堆栈跟踪

ios - Youtube iframe 未显示在 UIWebView 中

ios - 如何在 iOS 7 上更改 Reorder Control 图像

ios - 如何在加载 tableView 后更新 UITableViewCell 高度

ios - 我想在 iPad 应用程序中创建一个行为类似于操作表的自定义 View

ios - 如何在单个 UILabel 文本上获取两个普通字符串和 NSMutableString?