2010-05-17 29 views

回答

15

嘗試這種情況:

UIActionSheet *popupSheet = [[UIActionSheet alloc] initWithTitle:@"Title" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:@"No Way !" 
               otherButtonTitles:nil]; 

popupSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; 
UIButton * disclosureButton = (UIButton *)cell.accessoryView; 

[popupSheet showFromRect:disclosureButton.bounds inView:cell.accessoryView animated:YES]; 
[popupSheet release]; 

UIActionSheet docs狀態下showFromRect:inView:animated:方法:動作片在酥料餅,其箭頭指向視圖的指定矩形

顯示器(在我們的例子中詳細披露按鈕)。彈出窗口不與指定的矩形重疊。

0

我用這個更高級的使用:

  1. 發現定製accesoryView(cell.accesoryView)
  2. 如果是空的,發現產生accesoryView(UIButton的),如果電池有
  3. 如果UIButton不存在,找到單元格環境視圖(UITableViewCellContentView)
  4. 如果單元環境視圖不存在,請使用單元格視圖

可用於UIActionSheetUIPopoverController

這裏是我的代碼:

UIView *accessoryView  = cell.accessoryView; // finds custom accesoryView (cell.accesoryView) 
if (accessoryView == nil) { 
    UIView *cellContentView = nil; 

    for (UIView *accView in [cell subviews]) { 
     if ([accView isKindOfClass:[UIButton class]]) { 
      accessoryView = accView; // find generated accesoryView (UIButton) 
      break; 
     } else if ([accView isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) { 
      // find generated UITableViewCellContentView     
      cellContentView = accView; 
     } 
    } 
    // if the UIButton doesn't exists, find cell contet view (UITableViewCellContentView)   
    if (accessoryView == nil) { 
     accessoryView = cellContentView; 
    } 
    // if the cell contet view doesn't exists, use cell view 
    if (accessoryView == nil) { 
     accessoryView = cell; 
    } 
} 

[actionSheet showFromRect:**accessoryView.bounds** inView:**accessoryView** animated:YES]; 

中的iOS 4.3測試5.1

最好的自定義的方法來使用:

-(UIView*)getViewForSheetAndPopUp:(UITableViewCell*)cell; 

和方法代碼:

-(UIView*)getViewForSheetAndPopUp:(UITableViewCell*)cell { 
UIView *accessoryView = cell.accessoryView; 

if (accessoryView == nil) { 
    UIView *cellContentView = nil; 

    for (UIView *accView in [cell subviews]) { 
     if ([accView isKindOfClass:[UIButton class]]) { 
      accessoryView = accView; 
      break; 
     } else if ([accView isKindOfClass:NSClassFromString(@"UITableViewCellContentView")]) {    
      cellContentView = accView; 
     } 
    }  

    if (accessoryView == nil) { 
     accessoryView = cellContentView; 
    } 
    if (accessoryView == nil) { 
     accessoryView = cell; 
    } 
} 

return accessoryView; 
}