声明的未声明标识符?

时间:2012-06-20 01:29:30

标签: iphone ios xcode exc-bad-access undeclared-identifier

我正在创建一个应用程序,如果网页没有加载,它会出错并返回上一个屏幕。但是,在执行此操作后,在所有代码之后,获取未声明的标识符

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

2 个答案:

答案 0 :(得分:2)

对象cats在本地定义为viewDidLoad。变量的范围不会扩展到方法之外,因此doPop不知道猫是什么。

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

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

您在doPop中调用的方法中有拼写错误方法为dismissWithClickedButtonIndex:1 animated:YES];您有dissmissWithClickedButtonIndex:1 animated:YES];

此外,您只需要使用IBOutlet

定义@property

答案 1 :(得分:-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];

在View Did Load