2013-01-03 181 views
2

我有一個表格視圖,當用戶選擇一個特定的行時,我想顯示一個簡單的操作表來選擇新的條目是來自現有的聯繫人,還是創建一個新的聯繫人。我顯示該動作片作爲這樣:UIActionSheet不顯示在彈出窗口

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row != 0 ) 
    { 
     //Select the entry 
    } 
    else 
    { 
     UITableViewCell *selectedRow = [tableView cellForRowAtIndexPath:indexPath]; 
     UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"New Contact", @"Existing Contact", nil]; 

     [sheet showFromRect:selectedRow.frame inView:tableView animated:YES]; 
     return; 
    } 

    //Do some other stuff... 

}

根據文檔...

討論

在iPad上,這種方法顯示的操作片在酥料餅 其箭頭指向視圖的指定矩形。彈出框 不與指定的矩形重疊。

然而...行動表顯示在我的視圖的底部,而不是彈出到一邊。 tableview是一個splitviewcontroller中的主視圖

任何想法爲什麼這不起作用?

回答

0

而不是從的tableView大跌眼鏡,嘗試轉換單元邊界到最視圖(控制器,並從那裏彈出它...

CGRect frame = [self.view convertRect:cell.bounds fromView:cell]; 
[sheet showFromRect:frame inView:self.view animated:YES]; 

可能是,還有的的tableView內更多層次的情況和它打破你的東西

+0

試過這個:'CGRect frame = [selectedRow convertRect:selectedRow.frame toView:self.view]; [sheet showFromRect:frame inView:self.view animated:YES];'雖然沒有用,但同樣的確切行爲 –

1

我有同樣的問題,這個答案來幫助我。

Using UIActionSheet on iPad

如果你從一個的UIBarButtonItem或UIToolbar 是已經 一個酥料餅它,然後以類似的方式展現爲在 iPhone

事情是對我的內心表現出來,該表顯示爲分割視圖,並且在橫向上顯示該表格是作爲彈出窗口顯示的(橫向面板,您可以通過輕掃進行隱藏),因此,一旦將設備轉爲橫向模式,UIActionSheet就會在彈出窗口中顯示。原因是我大膽的:它不能在另一個popover中顯示爲popover。