视图之间的数据UIApplication [英] data between Views UIApplication
问题描述
我想在视图之间共享数据...
我有tabbar应用程序的appdelegate:
myappdelegate.h
#import< UIKit / UIKit .h>
@interface myappdelegate:NSObject< UIApplicationDelegate,UITabBarControllerDelegate> {
UIWindow * window;
UITabBarController * tabBarController;
NSString * result;
}
@property(非原子,保留)IBOutlet UIWindow *窗口;
@property(nonatomic,retain)IBOutlet UITabBarController * tabBarController;
@property(copy,readwrite)NSString * result;
@end
如果我想用这个命令,有提示:可能不回应....
myappdelegate * dataCenter = [(myappdelegate *)[ UIApplication sharedApplication] delegate]; <<可以不响应
dataCenter.result = @msg;
result_view * resultView = [[result_view alloc] initWithNibName:@result_viewbundle: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];
//从其笔尖加载视图后,请执行任何其他设置。
}
程序崩溃...
你的代码是说 sharedApplication
是类 myappdelegate
,确实没有回应委托
。这样做:
(myappdelegate *)[[UIApplication sharedApplication] delegate];
删除警告。
由于Objective-C的运行时消息传递,您当前的(警告生成)代码不会崩溃应用程序。崩溃在别的地方。
i want to share data between views...
i have the appdelegate of tabbar application:
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
- (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
. 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. The crash lies somewhere else.
这篇关于视图之间的数据UIApplication的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!