2012-06-20 152 views
0

我正在做一個應用程序,如果網頁沒有加載,它會給出錯誤並返回到前一個屏幕。然而,在這樣做,畢竟代碼,獲得一個未聲明的標識符已聲明的未聲明標識符?

#pragma mark - View lifecycle 


- (void)viewDidLoad 
{ 
    UIAlertView *cats = [[UIAlertView alloc] initWithTitle:@"**Read this first!**" 
                message:@"Thank you for ..." 
                delegate:nil 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:nil]; 
    [cats show]; 
    [catscroll setScrollEnabled:YES]; 
    [catscroll setContentSize:CGSizeMake(320,4800)]; 
    [catscroll setPagingEnabled:NO]; 
    [catform loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.petfinder.com/s/showPage.do?siteId=76333&pageId=7133416&shelterId=MA84&navigateToPage=Adopt%20Pets"]]]; 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)doPop 
{ 
    [cats dissmissWithClickedButtonIndex:-1 animated:YES]; 
    [self.navigationController popViewControllerAnimated:YES]; 
    UIAlertView *noconnectcatform = [[UIAlertView alloc] initWithTitle:@"Check your connection!" 
                   message:@"Cannot connect to FPP Servers.\nPlease check your Internet Connection\nYou may not proceed until you are connected via a cellular network." 
                   delegate:nil cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 
    [noconnectcatform show]; 
} 

,你可以在此圖像中看到。如果網頁未加載,則激活doPop,它返回視圖並顯示消息。然而,這是拋出一個EXC_BAD_ACCESS,因爲,你可以看到,在viewDidLoad方法下,還有另一個播放的消息。該應用程序變得困惑和崩潰。我試圖通過解除doPop方法中的警報來解決這個問題,但奇怪地給我這個錯誤。我可能會誤解,但不是它定義的「UIAlertView * cats」的alertview?爲什麼它說它沒有在doPop方法中定義?請幫忙!

+0

在堆棧溢出中使用代碼格式複製粘貼代碼,否則太麻煩,無法檢查我們。其實沒關係,在這種情況下,你的圖像質量足夠高。 – Pochi

+0

好吧:Couln't不知道StackOverflow格式,但這裏是pastie.org鏈接:http://pastie.org/4117873 –

+0

嘗試設置消息的代表有錯誤爲零。 – Pochi

回答

2

對象cats在本地定義爲viewDidLoad。該變量的範圍不會超出該方法,因此doPop不知道什麼是貓。

cats移動到在.h文件中定義爲成員/類變量。

這意味着您需要從viewDidLoad中刪除UIAlertView *,只需引用貓(因爲您正在定義範圍爲viewDidLoad的其他變量)。

你有叫doPop方法的錯字的方法dismissWithClickedButtonIndex:1 animated:YES];你有dissmissWithClickedButtonIndex:1 animated:YES];

而且,你只需要與@property

+0

這就是我實際上開始思考的問題。感謝您澄清!我確實試圖在全球範圍內定義它,但它給了我一個不同的錯誤。讓我解決它。 –

+0

我將下面評論中的pastie鏈接更新爲我的新代碼。我現在得到這個錯誤:'UIAlertView'沒有可見的@interface聲明扇區'dismissWithClickedButtonIndex:animated –

+0

Updated .m:http://pastie.org/4117873 Updated .h:http://pastie.org/4117942 –

-1

好吧定義IBOutlet,所以如果我是你,我會簡單地顯示該視圖上的錯誤消息未能加載,然後使用默認的取消操作來彈出此視圖(這是最常見的做法)

或者,如果您確實想在其他視圖中顯示消息,那種觀點顯示錯誤信息。有幾種方法可以做到這一點,但編號仍然與第一個選項。 (我可以告訴你如何,如果你真的想採取這種方法)

編輯:如果你只是想這個錯誤走開,在你的.m文件「實施」前加

@interface CatForm() 
{ 
    UIAlertView *cats; 
} 

@end 

,改變

UIAlertView *cats = [[UIAlertView alloc] initWithTitle:@"**Read this first!**" 
                    message:@"Thank you for considering to adopt a cat from our shelter. PLEASE READ THIS FORM CAREFULLY.\n\nThis on-line form is intended to assist you in selecting a cat that is suitable for you, your family, and your lifestyle.\n\nThe Friends of the Plymouth Pound have established guidelines and policies that must be met in order for your pre-screening application to be approved.\n\nThe information you provide is essential to facilitate the application review process.\n\nIn order to be considered for adoption by the Friends of the Plymouth Pound, you must:\n\n\n*Be at least 18 years old.\n\n*Provide all the applicable information requested below.\n\n**Note, any data field marked with an asterisk character (*) must be filled in. Incomplete application forms will not be considered for review and will be denied automatically.**\n\n*Understand that this is a pre-screening form.\n\n\nThe Friends of the Plymouth Pound will contact you and approve you if, and only if, all requirements have been met.\n\nUpon review of your pre-screening application, you will be contacted by the Friends of the Plymouth Pound to notify you if your application has been accepted and if further information is needed. \n\n\n**Please note that we do contact all personal references and veterinarians, and we must speak with them personally. In addition, in some cases, a pre-adoption home visit may also be required.**\n\nIn the event that your pre-screening application has been not been approved, we will notify you of same.\n\n\nTHE BOARD OF DIRECTORS OF THE FRIENDS OF THE PLYMOUTH POUND RESERVES THE RIGHT TO DENY ANY PRE-APPLICATION BASED ON THE ORGANIZATION'S ESTABLISHED STANDARDS AND POLICIES, INCLUDING, BUT NOT LIMITED TO, INCOMPLETE INFORMATION, NON-DISCLOSURE OR OMISSION OF PERTINENT FACTS, AND NON-COMPLIANCE WITH ACCEPTED STANDARDS.\n\n\nUpon approval of your application and transfer of the animal, you will be charged a $150.00 adoption fee per cat.\n\n\nWe are an all-volunteer organization. Due to the high volume of applications, we ask that you be patient in waiting for a reply. Please do not submit duplicate applications or separate requests for response. Doing this will not accelerate the review process in any way." 
                   delegate:self cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil]; 

cats = [[UIAlertView alloc] initWithTitle:@"**Read this first!**" 
                    message:@"Thank you for considering to adopt a cat from our shelter. PLEASE READ THIS FORM CAREFULLY.\n\nThis on-line form is intended to assist you in selecting a cat that is suitable for you, your family, and your lifestyle.\n\nThe Friends of the Plymouth Pound have established guidelines and policies that must be met in order for your pre-screening application to be approved.\n\nThe information you provide is essential to facilitate the application review process.\n\nIn order to be considered for adoption by the Friends of the Plymouth Pound, you must:\n\n\n*Be at least 18 years old.\n\n*Provide all the applicable information requested below.\n\n**Note, any data field marked with an asterisk character (*) must be filled in. Incomplete application forms will not be considered for review and will be denied automatically.**\n\n*Understand that this is a pre-screening form.\n\n\nThe Friends of the Plymouth Pound will contact you and approve you if, and only if, all requirements have been met.\n\nUpon review of your pre-screening application, you will be contacted by the Friends of the Plymouth Pound to notify you if your application has been accepted and if further information is needed. \n\n\n**Please note that we do contact all personal references and veterinarians, and we must speak with them personally. In addition, in some cases, a pre-adoption home visit may also be required.**\n\nIn the event that your pre-screening application has been not been approved, we will notify you of same.\n\n\nTHE BOARD OF DIRECTORS OF THE FRIENDS OF THE PLYMOUTH POUND RESERVES THE RIGHT TO DENY ANY PRE-APPLICATION BASED ON THE ORGANIZATION'S ESTABLISHED STANDARDS AND POLICIES, INCLUDING, BUT NOT LIMITED TO, INCOMPLETE INFORMATION, NON-DISCLOSURE OR OMISSION OF PERTINENT FACTS, AND NON-COMPLIANCE WITH ACCEPTED STANDARDS.\n\n\nUpon approval of your application and transfer of the animal, you will be charged a $150.00 adoption fee per cat.\n\n\nWe are an all-volunteer organization. Due to the high volume of applications, we ask that you be patient in waiting for a reply. Please do not submit duplicate applications or separate requests for response. Doing this will not accelerate the review process in any way." 
                   delegate:self cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil]; 

在查看有沒有加載

+0

你錯過了這一點。他正在手動解僱UIAlertView –

+0

這是應用程序在用戶手中的方式。如果用戶沒有互聯網連接,應用程序會發送一條錯誤信息(無所謂屏幕),但將用戶引導至前一屏幕(採用窗體選擇屏幕) –

+0

@SamGehly只需刪除貓dismisswithbutton點擊bla bla,你不需要它,沒有委託,如果你不覆蓋它的行爲,它會在用戶按下取消按鈕時自動解除。 – Pochi