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”的地方定义了警报视图吗?为什么它说它没有在doPop方法中定义?请帮忙!

4

2 回答 2

2

该对象cats在本地定义为viewDidLoad。变量的范围没有超出方法,因此doPop不知道猫是什么。

移动cats要在 .h 文件中定义为成员/类变量。

这意味着您需要UIAlertView *从内部删除viewDidLoad并仅引用猫(因为您正在定义另一个范围为 的变量viewDidLoad)。

您在调用的方法中有错字doPop The method is dismissWithClickedButtonIndex:1 animated:YES]; You havedissmissWithClickedButtonIndex:1 animated:YES];

此外,您只需要IBOutlet定义@property

于 2012-06-20T01:54:25.380 回答
-1

好的,所以如果我是你,我会简单地在加载失败的视图上显示错误消息,然后使用默认的取消操作来弹出这个视图(这是最常见的做法)

或者,如果您真的想在另一个视图中显示消息,则必须使该视图显示错误消息。有几种方法可以做到这一点,但 id 仍然使用第一个选项。(我可以告诉你如果你真的想采用这种方法)

编辑:如果您只是希望该错误消失,请在 .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];

在视图中加载

于 2012-06-20T02:05:48.077 回答