我已声明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”*。
更具体地说,我已经在 1stclass 中声明了这个UIAlertView
然后我正在比较 2ndclass 和 2ndclass <中的一些参数/ em>它正在调用具有此UIAlertView
的 1stclass 方法。
答案 0 :(得分: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");
}
}
你弄乱了方法名......
答案 1 :(得分:0)
是的,我使用并确认了它但是得到了解决方案,就像我必须创建@protocol类并在其中声明 - (void)方法然后在Appdelegate类中为它创建一个委托,并且oneclass。所以,我调用@protocol类方法,然后调用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];
}