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出现并单击“确定”选项时,它会崩溃并给我*“程序接收信号:“EXC_BAD_ACCESS”* 的错误。

更具体地说,我已经UIAlertView1stclass中声明了这个,然后我比较了 2ndclass 中的一些参数,并且2ndclass它正在调用具有 this 的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 类中为它创建一个委托,也在一个类中。所以,我调用了@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 回答