これは私が自分でやろうとしている私の最初のアプリですが、いくつか質問があります。私は4つのタブを持って、最初の "HomeView"というJSONデータを解析しています(これはこれまでに行われています)。iOSのタブ間でデータを渡す
しかし、私が望むのは、解析されているデータのいくつかが他のタブに表示されていることです(また、再度解析する必要はありません)。
#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」を見ることができます:HomeViewの私のコードの一部だから、
はこちらです。
だから、この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);
}
及び(ヌル)がプリントアウトされます。
だから、あなたが私のsollutionを提案することができ
#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
delegate.hアプリのコードを追加しましたか?
のmyPropertyは、自分の@propertyの名前かどうかですか?私はAppDelegate.mファイルにこのコードを置くべきですか? – ghostrider
myPropertyは@propertyの名前です。名前は任意に指定できます。あなたが作成したコードスニペットをビューコントローラに配置する必要があります。 – scord
@property(nonatomic、retain)NSString * myPropertyは、アプリケーションデリゲートの.hファイルに入ります – scord