我想在视图之间共享数据......
我有tabbar应用程序的appdelegate:
myappdelegate.h
#import <UIKit/UIKit.h>
@interface myappdelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
NSString *result;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (copy , readwrite) NSString *result;
@end
如果我想使用此命令调用,则有提示:“可能无法响应”....
myappdelegate *dataCenter = [(myappdelegate *)[UIApplication sharedApplication] delegate]; <<may not respond
dataCenter.result = @"msg";
result_view *resultView = [[result_view alloc] initWithNibName:@"result_view" bundle:nil];
[self.navigationController pushViewController:resultView animated:YES];
[resultView release];
result_view.m
- (void)viewDidLoad
{
myappdelegate *dataCenter = (myappdelegate*)[[UIApplication sharedApplication]delegate];
[label setText:dataCenter.result];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
程序崩溃......
答案 0 :(得分:0)
您的代码说sharedApplication
属于myappdelegate
类,它确实不响应delegate
。这样做:
(myappdelegate *)[[UIApplication sharedApplication] delegate];
删除警告。
由于Objective-C的运行时消息传递,您当前的(生成警告)代码不会使应用程序崩溃。崩溃发生在其他地方。
答案 1 :(得分:0)
你的第一行应该是
myappdelegate *dataCenter = (myappdelegate *)[[UIApplication sharedApplication] delegate];
关于第二行,我不知道你期望发生什么。您的myappdelegate类上没有result_array属性,因此您当然无法设置该属性。
如果您尝试设置result
属性,则应该编写
dataCenter.result = @"msg";