[英]UIButton not clickable in UITableViewCell
我在用工具欄包裹的UITableViewCell
添加了多個按鈕,但是所有這些按鈕都是不可單擊的,一旦我將按鈕拖動到表格視圖的外部,它就已經可以單擊了。
這是我的示例應用程序和場景的屏幕截圖:
按鈕1是不可單擊的,但是按鈕2是可單擊的,已選中“啟用用戶交互”。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
cell.button.tag = indexPath.row
cell.button.addTarget(self, action: "btnClicked:", forControlEvents: .TouchUpInside)
}
像這樣在viewForHeaderInSection
創建您的按鈕。
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[sectionView addSubview:btn];
//add other subviews to section viewww..
//return
return sectionView;
}
- (void) btnClicked
{
//do your thing here..
}
好的,已經發現了問題,這是我自己的錯誤,這是因為我將tableViewCell的“ User Interaction Enabled”設置為NO,這是因為我想禁用Table View默認行選擇。
因此,我需要將“啟用用戶交互”的每個視圖層設置為“是”,然后可以單擊該按鈕,感謝所有答復!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.