3
我在ViewController
以外的班级中有UIAlertView
代表团遇到问题。 一切都很好,直到用户点击按钮OK
- 然后应用程序崩溃与UIAlertViewDelegate在单独的班级崩溃应用程序
Thread 1: EXC_BAD_ACCESS (code=2, address 0x8)
ViewController.h:
#import <UIKit/UIKit.h>
#import "DataModel.h"
@interface ViewController : UIViewController
@end
ViewController.m:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
DataModel *dataModel = [[DataModel alloc] init];
[dataModel ShowMeAlert];
[super viewDidLoad];
}
@end
的DataModel .h
#import <Foundation/Foundation.h>
@interface DataModel : NSObject <UIAlertViewDelegate>
- (void)ShowMeAlert;
@end
DataModel.m
#import "DataModel.h"
@implementation DataModel
- (void)ShowMeAlert;
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Info" message:@"View did load!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
#pragma mark - UIAlertView protocol
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"Index: %d", buttonIndex);
}
@end
- 如果显示警报和它的授权方法的代码是
ViewController
- 完美的作品。 - 当我删除
UIAlertDelegation
方法...didDismissWithButtonIndex...
- 没有委派的作品。 - 当我设置
UIAlertView delegate
到nil
- 没有委托的作品。
任何线索有什么不对?
谢谢一堆 - 它的作品!我有很多东西要学习...... – gutaker