[英]data between Views UIApplication
i want to share data between views... 我想在视图之间共享数据...
i have the appdelegate of tabbar application: 我有标签栏应用程序的appdelegate:
myappdelegate.h
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
if i want to call with this command, there is the hint: "may not respond".... 如果我想使用此命令进行调用,则提示:“可能不响应” ....
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
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.
}
the program crashes... 程序崩溃了...
Your code is saying that the sharedApplication
is of the class myappdelegate
, which indeed does not respond to delegate
. 您的代码是说,
sharedApplication
是类的myappdelegate
,这的确不响应delegate
。 Do this: 做这个:
(myappdelegate *)[[UIApplication sharedApplication] delegate];
to remove the warning. 删除警告。
Due to Objective-C's runtime messaging, your current (warning-generating) code won't crash the app. 由于Objective-C的运行时消息传递,您当前的(警告生成)代码不会使应用程序崩溃。 The crash lies somewhere else.
飞机坠毁发生在其他地方。
Your first line should be 您的第一行应该是
myappdelegate *dataCenter = (myappdelegate *)[[UIApplication sharedApplication] delegate];
As for the second line, I can't tell what you expect to happen. 至于第二行,我无法告诉您您期望发生什么。 You don't have a result_array property on your myappdelegate class, so of course you can't set that property.
您的myappdelegate类上没有result_array属性,因此当然不能设置该属性。
If you were trying to set the result
property, you should have written 如果您尝试设置
result
属性,则应编写
dataCenter.result = @"msg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.