我有一個表視圖作爲我的RootViewController,並用此代碼按下按鈕上的另一個按鈕。未在新視圖控制器中調用按鈕操作
[[self navigationController] pushViewController:aboutVC animated:YES];
我的問題是,我的按鈕的操作時,他們被按下時不會被調用。我已經檢查了幾乎所有我能想到的內容,並且我非常肯定地看到有一個視圖超出了攔截用戶交互的按鈕。除了在我的新視圖控制器中編碼的按鈕及其動作,我沒有別的。我正在使用一個自定義單元格,但其中沒有任何內容。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
cell.userInteractionEnabled = NO;
//ADD BUTTONS
UIButton *redButton = [[UIButton alloc] init];
redButton.backgroundColor = [UIColor colorWithRed:0.0/255 green:0.0/255 blue:0.0/255 alpha:1.00];
[redButton addTarget:self action:@selector(redButton:) forControlEvents:UIControlEventTouchUpInside];
redButton.frame = CGRectMake(9, 44, 40, 39);
[cell addSubview:redButton];
[redButton release];
return cell;
}
- (void)redButton:(id)sender
{
//Button action will go here
}
關於我可能會做錯什麼的任何想法?
設置cell.userInteractionEnabled = YES;然後動作會調用,並像這樣添加按鈕[cell.contentView addSubview:redButton]; – Narayana
@Narayana - 我剛要回答,但您的評論首先出現。你能發表答覆嗎? – bryanmac
我嘗試過,沒有運氣。據我瞭解,單元不需要啓用用戶交互,因爲按鈕用戶交互是一個單獨的設置。這是我在我的RootViewController中做到的,它工作正常。 – user1072515