0
我正在嘗試使用下面的代碼向我的表視圖節標題中添加單擊手勢。但是它不會在返回的視圖中嵌入手勢。我在這裏做錯了什麼?非常感謝你的幫助。將手勢動態添加到現有的表格視圖節標題
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [tableView headerViewForSection:section];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissKeyBoard)];
[view addGestureRecognizer:singleTap];
return view;
}
感謝Edwin的快速反應,但我擔心它沒有解決問題。但是,如果我嘗試創建如下所示的視圖,並指定它的工作正常。 UIView * view = [[UIView alloc] init];只有當我嘗試分配現有標題部分時,它才起作用。 –
在那種情況下,我認爲你的問題是[tableView headerViewForSection:section]返回nil。你首先需要註冊一個類或筆尖來處理。看到這個http://stackoverflow.com/questions/15231726/uitableview-headerviewforsection-always-returns-nil –
上帝..非常感謝埃德溫。這是確切的問題。它返回null。我需要註冊一個筆尖。再次感謝。 –