我已經創建了一個自定義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