繁体   English   中英

Views UIApplication之间的数据

[英]data between Views UIApplication

我想在视图之间共享数据...

我有标签栏应用程序的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.
}

程序崩溃了...

您的代码是说, sharedApplication是类的myappdelegate ,这的确不响应delegate 做这个:

(myappdelegate *)[[UIApplication sharedApplication] delegate];

删除警告。


由于Objective-C的运行时消息传递,您当前的(警告生成)代码不会使应用程序崩溃。 飞机坠毁发生在其他地方。

您的第一行应该是

myappdelegate *dataCenter = (myappdelegate *)[[UIApplication sharedApplication] delegate];

至于第二行,我无法告诉您您期望发生什么。 您的myappdelegate类上没有result_array属性,因此当然不能设置该属性。

如果您尝试设置result属性,则应编写

dataCenter.result = @"msg";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM