これは私が自分でやろうとしている最初のアプリで、いくつか質問があります。4 つのタブが必要で、「HomeView」という名前の最初のタブで、JSON データを解析しています (これまでのところ完了しています)。
しかし、私が望むのは、他のタブに表示されるように解析されているデータの一部です (再度解析する必要はありません)。
したがって、HomeView の私のコードの一部は次のとおりです。
#import "HomeView.h"
@interface HomeView ()
@end
@implementation HomeView
//other code
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//data fetched
parsed_date=[res objectForKey:@"date"];
NSLog(@"Date:%@",parsed_date);
[UIAppDelegate.myArray addObject:parsed_date];
}
「parsed_date」が正しく出力されていることがわかります。
したがって、この parsed_date が OtherView に表示されるようにします。
これは私のコードですが、印刷できません。
OtherView.m
#import "OtherView.h"
#import "HomeView.h"
#import "AppDelegate.h"
@interface OtherView ()
@end
@implementation OtherView
@synthesize tracks_date;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//preview value of other class
tracks_date = [UIAppDelegate.myArray objectAtIndex:0];
NSLog(@"Dated previed in OtherView: %@", tracks_date);
}
および (null) が出力されています。
アプリの delegate.h のコードを追加
#import <UIKit/UIKit.h>
#define UIAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) NSArray *myArray;
@end
それで、解決策を提案してもらえますか?