0

我创建了一个自定义UITableViewCell,它作为子视图添加到我的视图中。在这个视图中也有 aa UITableView。自定义UITableViewCell不是(包含)到UITableView.

我已经UITableViewCell像这样在我的 viewDidLoad 方法中设置了自定义。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Create custom tableviewCell at top of screen under navigation controller

    cellContainer = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
    cellContainer.backgroundColor = [UIColor whiteColor];

    UITableViewCell *mycell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 50.0)];
    mycell.textLabel.text = @"Select all";
    mycell.backgroundColor = [UIColor whiteColor];


    [cellContainer addSubview:mycell];
    [self.view insertSubview:cellContainer atIndex:1];

    // Set table positioning
    [subModelTableView setFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height - 44)];
    [self.view insertSubview:subModelTableView atIndex:0];

    // set tableview datasource and delegate
    [subModelTableView setDelegate:self];
    [subModelTableView setDataSource:self];
}

目前我无法选择这个自定义表格视图单元格,我试图像这样在它上面设置一个选择器

[mycell addTarget:self action:@selector(myAwesomeMethod:) forControlEvents:UIControlEventTouchUpInside];

但我收到一个错误

No visible @interface for 'UITableViewCell' declares the selector 'addTarget:action:forControlEvents:'

所以我想知道是否有另一种方法(正确的方法)或者我是否在正确的轨道上,我该如何解决这个错误?

UITableViewCell编辑:我在这个视图中有这个额外的原因是它UINavigationBar作为一个带有@“全选”的静态单元格位于下面,这个单元格位于上面UITableView但看起来被包含在UITableView但显然不是。

当用户滚动UITableView值时,如果用户不知道他想选择哪个单元格,我想启用@“全选”单元格,因此他会收到一个值列表,代表选择UITableView. 我希望这是有道理的。

4

1 回答 1

0

所以我想知道是否有另一种方法(正确的方法)或者我是否在正确的轨道上,我该如何解决这个错误?

我认为这不是正确的做法。我认为您应该使用 UITableViewDelegate 的 didSelectRowAtIndexPath 方法。如果这不起作用,请详细说明您要做什么,以便提供更好的建议。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html

于 2012-08-22T20:58:40.887 回答