我已经创建了一个自定义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
。我希望这是有道理的。
试试[mycell.contentView addTarget ...] – CSmith
仍然给我一个错误,甚至把那个错误是不同的,但还是一样.. **无可见@interface用于清洗后的项目'UIView'声明了选择器'addTarget:action:forControlEvents:'** – HurkNburkS
是的,addTarget是一个UIControl类的方法,所以你只能在UIControl的视图后代(比如UIButton)上做到这一点。你需要看看处理原始触摸事件... – CSmith