[英]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.