2013-07-29 62 views
0

在我的應用程序中,當我點擊更改圖像時,它會詢問UIActionsheet有三個操作拍照,選擇圖庫並取消。拍照,從圖庫中選擇顯示但取消不顯示問題出在哪裏。 這是我的代碼在UIActionSheet取消按鈕不顯示iPhone?

- (void)viewDidLoad 
{ 
     [super viewDidLoad]; 
     UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." 
     delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil]; 
     actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
     actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 
     [actionSheet showInView:self.view]; 
} 
+0

你有一次'{'兩次,'}'。 – Daniel

+0

這段代碼不是問題。我創建了一個新項目,並使用了你的代碼(只有一個'''')。它按預期工作。我得到一個帶有3個按鈕的操作表:「拍照」和「從庫中選擇」爲淺灰色,以及「取消」按鈕,深灰色,標題爲「Select Image from ...」 – Daniel

+0

您是否在應用中使用了tabBar ? – Apple

回答

2

它,因爲...我想你使用的是默認視圖大小-Retina 4全屏幕視圖大小...只需嘗試將視圖大小從「屬性」檢查器更改爲Retina 3.5全屏幕即可!

+0

是的這個問題你說它是正確的Thankyou所有 – user2576173

+0

該問題中的代碼適用於iPhone,iPhone 3,5「和iPhone 4」(測試) – Daniel

1

試試這個...

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:@"Cancel" 
               otherButtonTitles:@"Take Photo", @"Choose from library", nil]; 

    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 
    [actionSheet showInView:self.view]; 
+0

夫婦的事情,你不需要爲代理投入id,破壞性按鈕與取消按鈕不一樣,並且此代碼仍然將樣式設置保持爲一選項,然後立即將其設置爲另一個。 –

+0

@Abhijith我試過了這是拋出異常2013-07-29 16:21:48.273 TestIGate [14936:c07] actionSheet 2013-07-29 16:21:49.087 TestIGate [14936:c07] ***終止應用程序,由於未捕獲的異常 'NSInvalidArgumentException',理由是: '源型不可用' ***第一擲調用堆棧: (0x1c9f012 0x10dce7e 0x2249d9 0x4278 0x416d 0x4012c1 0x10f0705 0x27920 0x278b8 0xe8671 0xe8bcf 0xe7d38 0x5733f 0x57552 0x353aa 0x26cf8 0x1bfadf9 0x1bfaad0 0x1c14bf5 0x1c14962 0x1c45bb6 0x1c44f44 0x1c44e1b 0x1bf97e3 0x1bf9668 0x2465c 0x28fd 0x2825) libC++ abi.dylib:終止調用拋出異常 (lldb) – user2576173

+0

是不是你的項目使用ARC? –

1

你可能想看看在class reference呈現動作片的替代方法。但是,您可能想嘗試使用以下步驟之一(如果你有一個工具欄)

– showFromBarButtonItem:animated: 
– showFromToolbar: 

此外,使用以下

actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent; 
actionSheet.actionSheetStyle = UIActionSheetStyleDefault; 

僅會導致動作片風格的存在違約。

0

請參考this link

而且你可以參考下面的代碼還,它可以幫助你:

(void)viewDidLoad 
    { 

    UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Image from..." delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take Photo", @"Choose from library", nil]; 
    [actionSheet showInView:self.view]; 

    } 
+0

取消按鈕不會出現在上面的代碼 – user2576173

+0

請查看我給出的上述鏈接。它的一個例子UIActionSheet – Mital

0

由於您的問題不在您的代碼。也許你正在使用錯誤的方法來顯示你的UIActionSheet。

一個UIActionSheet可以用以下方法顯示:

– showFromTabBar: 
– showFromToolbar: 
– showInView: 
– showFromBarButtonItem:animated: 
– showFromRect:inView:animated: 

看看Apple's UIActionSheet reference

由於您使用TabBar,取消按鈕也可能在下面。我也會測試。

+0

請爲我提供上述方法的示例代碼 – user2576173

+0

也許你可以嘗試:[[actionSheet showInView:[UIApplication sharedApplication] .keyWindow];'。這可能會解決TabBar的問題,以防萬一。 – Daniel

相關問題