2011-03-23 44 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

相關問題