我在我的iPhone應用程序中有自定義標題視圖。它有一個自定義按鈕。 但是這個自定義按鈕動作並不火,而是觸發了自定義類中的標題點擊事件。請幫助我。如何在標題視圖中的按鈕上觸發動作。自定義TableView問題
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSNumber *num=[NSNumber numberWithInt:section];
UIView * customView = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,50)]autorelease];
customView.tag = section;
[customView setUserInteractionEnabled:YES];
customView.backgroundColor = [UIColor blackColor];
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(260, 7, 25, 25);
button.tag=section;
[button addTarget:self action:@selector(expandCollapsing:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"add.png"] forState:UIControlEventTouchUpInside];
[button setSelected:YES];
}
能否請您發佈您的代碼,這樣我們就可以幫你? – 2012-03-20 06:55:19
嘿,只是取代我最近發佈的片段。它將解決您點擊的問題,即使您不需要使用自定義視圖或手勢。 – Kuldeep 2012-03-20 07:57:58
您錯過了代碼中返回視圖的部分,或將該按鈕作爲子視圖添加到customView。我認爲這只是從問題而不是從你的代碼中丟失? – jrturton 2012-03-20 08:15:10