我已经创建了一个自定义的 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/