0

UIAlertViewDelegate私はこのようにそのメソッドを呼び出すことを宣言しました

-(IBAction)hidding{
    [self removeFromParentViewController];
    UIAlertView *alert1= [[UIAlertView alloc] initWithTitle:@"Logged in"
        message:[NSString stringWithFormat:@"Welcomes you"]
        delegate:self
        cancelButtonTitle:@"Ok"
        otherButtonTitles:nil];
    [alert1 show];
}


- (void)alertViewUIAlertView *)actionSheet clickedButtonAtIndexNSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons
    NSLog(@"clicking");
    if (buttonIndex == 0)
    {
        NSLog(@"ok");
    }
    else
    {
        NSLog(@"cancel");
    }
}

どのボタンがクリックされたかを確認し、何らかのアクションを実行します。ただし、UIAlertViewが表示され、[OK]オプションをクリックするとクラッシュし、* "プログラム受信信号:" EXC_BAD_ACCESS"*のエラーが表示されます。

具体的には、これUIAlertView1stclassで宣言し、2ndclassでいくつかのパラメーターを比較しています。2ndclassから、これを持つ1stclassメソッドを呼び出していますUIAlertView

4

2 に答える 2

1
- (void)alertViewUIAlertView *)actionSheet clickedButtonAtIndexNSInteger)buttonIndex
{
    // the user clicked one of the OK/Cancel buttons
    NSLog(@"clicking");
    if (buttonIndex == 0)
    {
        NSLog(@"ok");
    }
    else
    {
        NSLog(@"cancel");
    }
}

その方法は私には非常に奇妙に見えます。このようにする必要があります:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // the user clicked one of the OK/Cancel buttons
    NSLog(@"clicking");
    if (buttonIndex == 0)
    {
        NSLog(@"ok");
    }
    else
    {
        NSLog(@"cancel");
    }
}

メソッド名をめちゃくちゃにしました...

于 2012-04-29T09:00:14.913 に答える
0

はい、使用して確認しました。ただし、解決策は、@ protocolクラスを作成し、その中で-(void)メソッドを宣言してから、そのAppdelegateクラスとoneclassにデリゲートを作成する必要があるようなものでした。そこで、@ protocolクラスメソッドを呼び出し、次にoneclassメソッドを呼び出します。注:oneclassで@protocolメソッドを継承し、問題が解決しました。これがソリューションの完全なコードです。これは@protocol.hクラスです。

#import <Foundation/Foundation.h>
 #import <UIKit/UIKit.h>

@protocol SMLoginDelegate 

- (void)didDisconnection;
@end

This is my oneclass

#import "oneclass.h"

@interface oneclass : UIViewController<UITextFieldDelegate,SMLoginDelegate>
{


}
@end

oneclass.m

- (void)viewDidLoad
{

    [super viewDidLoad];

     AppDelegate *del1 = [self appDelegate];
    del1._loginDelegate = self;

    // Do any additional setup after loading the view from its nib.
}


appdelegate.h class
@interface FirstphaseAppDelegate {
__weak NSObject <SMLoginDelegate> *_loginDelegate;
}
@property (nonatomic, weak) id _loginDelegate;

appdelegate.m class

@synthesize _loginDelegate;

-(void)anymethod
{
[_loginDelegate didDisconnection];
}
于 2012-04-30T08:45:53.047 に答える