2012-08-22 30 views
0

我已经创建了一个自定义UITableViewCell,作为子视图添加到我的视图。在这个视图中还有一个UITableView。自定义UITableViewCell不属于(包含)到UITableView设置自定义UITableViewCell选择器

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

- (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]; 
} 

是在我无法选择这个定制的tableview细胞瞬间的事情,我试图在像这样

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

设置一个选择,但我得到一个错误

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

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

编辑: 我之所以在此视图中有这样的额外UITableViewCell是,它坐在UINavigationBar下面,使用@静态细胞“全选”在里面,这种细胞坐在UITableView以上,但给被列入appeance在UITableView但显然不是。

当用户滚动值的UITableView如果用户不知道他想要选择哪个单元我想启用@“全选”单元,所以他收到一个值的列表,将代表选择每个单元格在UITableView。我希望这是有道理的。

+0

试试[mycell.contentView addTarget ...] – CSmith

+0

仍然给我一个错误,甚至把那个错误是不同的,但还是一样.. **无可见@interface用于清洗后的项目'UIView'声明了选择器'addTarget:action:forControlEvents:'** – HurkNburkS

+0

是的,addTarget是一个UIControl类的方法,所以你只能在UIControl的视图后代(比如UIButton)上做到这一点。你需要看看处理原始触摸事件... – CSmith

回答

0

所以我想知道是否有这样做 (有道)的任一种方式,或者如果我在正确的轨道上我怎样才能解决这个 错误?

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

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

+0

是的我想使用UITableViewDelegates但是它们已被使用也是在这个视图中的tableview。请检查我编辑的问题,以了解我正在尝试执行的操作。 – HurkNburkS

+0

是否有理由在一个视图中需要多个TableView? – Brian

+0

我在底部添加了一个我想要实现的内容的编辑。因为如果用户找不到他们希望选择的内容,他们可以选择@“select all” – HurkNburkS