0

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

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

结果视图.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.
}

程序崩溃...

4

2 回答 2

0

您的代码说的sharedApplication是类的myappdelegate,它确实没有响应delegate。做这个:

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

删除警告。


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

于 2011-03-23T15:36:49.143 回答
0

你的第一行应该是

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

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

如果你试图设置result属性,你应该写

dataCenter.result = @"msg";
于 2011-03-23T15:37:36.240 回答