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];
}

あなたがこの画像で見ることができるように。Webページがロードされない場合は、doPopがアクティブになり、ビューが返され、メッセージが表示されます。ただし、ご覧のとおり、viewDidLoadメソッドの下に別のメッセージが再生されるため、これはEXC_BAD_ACCESSをスローします。アプリが混乱してクラッシュしています。doPopメソッドでアラートを閉じることでこれを修正しようとしましたが、奇妙なことにこのエラーが発生します。誤解されているかもしれませんが、alertviewは「UIAlertView * cats」と表示されている場所で定義されていませんか?doPopメソッドで定義されていないというのはなぜですか?助けてください!

4

2 に答える 2

2

オブジェクトcatsはローカルでに定義されviewDidLoadます。変数のスコープはメソッドを超えて拡張されないため、doPop猫が何であるかはわかりません。

cats.hファイルでメンバー/クラス変数として定義されるように移動します。

UIAlertView *これは、猫を内部から削除し、猫を参照する必要があることを意味しますviewDidLoad(そのまま、スコープが別の変数を定義していますviewDidLoad)。

で呼び出されたメソッドにタイプミスがありますdoPop 。メソッドはdismissWithClickedButtonIndex:1 animated:YES]; あなたが持っていますdissmissWithClickedButtonIndex: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 に答える