2011-03-23 57 views
0

我想分享的观点之间的数据...数据的UIApplication

我有应用程序的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

由于属性被称为'result',不'result_array'。 – Jilouc 2011-03-23 15:34:30

+0

sry我只是改变了它... – Phil 2011-03-23 15:37:48

回答

0

你的代码是说,sharedApplication是类myappdelegate,这的确并不delegate回应。这样做:

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

删除警告。


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

+0

mmh多数民众赞成在... ...!没有警告了,但字符串没有被转移...之后,我会打开结果的视图...:result_view * resultView = [[result_view alloc] initWithNibName:@“result_view”bundle:nil]; [self.navigationController pushViewController:resultView animated:YES]; [resultView release]; – Phil 2011-03-23 15:50:26

0

你的第一行应该是

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

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

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

dataCenter.result = @"msg"; 
+0

我已更新我的帖子.. thx ^^ – Phil 2011-03-23 15:59:18

相关问题