2011-11-08 39 views
0

我新的目標C和我在我需要真正快速創建一個iPhone應用程序的位置,我使用的XCode 4.2UIalert視圖不工作

我希望有一個彈出,我使用驗證碼:

在.H我

#import <AddressBook/AddressBook.h> 
#import <AddressBookUI/AddressBookUI.h> 

,並在.m文件

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Confirmation" 
                message:@"confirmed" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil,nil]; 
          [alert show]; 

鱈魚e向我展示了一個建築錯誤「預期標識符」,我忘記了什麼?

感謝

+0

檢查括號匹配,parens,大括號只需雙擊一個,如果有匹配,選擇將highlite。很好的快速測試。 – zaph

+0

額外支架。在分配之前刪除它們之一。 – Jacob

+0

我的回答有幫助嗎? – Oliver

回答

1

您有一個額外的開括號 '['

你需要的東西是這樣的:

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Confirmation" 
                message:@"confirmed" 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil] autorelease]; 
          [alert show]; 

注意自動釋放]代碼我加了,這樣你設置爲自動釋放UIAlertView並修復額外的開放式支架。

+0

Xcode 4.2 - 所以我猜測OP的使用ARC,因此autorelease調用是不需要的。 –

+0

好點,然後不需要autorelease,只需刪除額外的開放括號=) –

+0

還要注意,他在'otherButtonTitles:'參數上使用了'nil'兩次......我懷疑這可能會造成傷害,但這不是好的做法當然 – Matoe

0

你有兩個錯誤:

->[<- [UIAlertView中頁頭] initWithTitle:@ 「確認」 消息:@ 「證實」 委託:自我 cancelButtonTitle:@ 「OK」 otherButtonTitles:無->,nil<-];

刪除它們,只是寫:

[[UIAlertView alloc] initWithTitle:@"Confirmation" 
          message:@"confirmed" 
          delegate:self 
       cancelButtonTitle:@"OK" 
       otherButtonTitles:nil]; 

如果你不使用ARC,不要忘記[alert show]後釋放[alert release](或autorelease在初始化結束)