Appleは、タブ間のページの読み込み時間が長すぎるというアプリの配置を拒否しました。以前は、CMSで管理されているコンテンツを表示するためにWebビューを呼び出すだけでした。これでJSONが実装され、シングルトンデザインパターンを使用して5つのタブのデータをプリロードしようとしています。例のようにシングルトン値を設定できないようです。コードについて:
header.h
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController {
NSString *someProperty;
...
}
@property (nonatomic, retain) NSString *someProperty;
+ (id)sharedManager;
@property (strong, nonatomic) NSString* tab3data;
@end
Implementation.m
//Create a seperate thread to download JSON thread
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) //1
//Set JSON URL
#define GWDiOSURL [NSURL URLWithString:@"http://m.web.org/cms_mapper.php"]
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
@synthesize someProperty;
- (id)init {
if (self = [super init]) {
someProperty = @"Default Property Value";
}
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"First", @"First");
self.tabBarItem.image = [UIImage imageNamed:@"first"];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
FirstViewController *sharedManager = [FirstViewController sharedManager];
NSLog(@"Toll%@",sharedManager);
// Do any additional setup after loading the view, typically from a nib.
//Get JSON and load into 'data'
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:GWDiOSURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
//Begin JSON Data Parsing and loading
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
//Parse JSON
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
// Load JSON into a dictionary
NSDictionary *tabData = [json objectForKey:@"mapper"];
// Get Tab3 data from dictionary
NSDictionary *tab3 = [tabData objectForKey:@"#tab3_content"];
// Load Tab3 data into a string from dictionary
NSString *html = [NSString stringWithFormat:@"%@",tab3];
// Verify content via counsel
//NSLog(@"Second Data:%@",html);
// Load content into webView
[webView loadHTMLString:html baseURL:nil];
[FirstViewController sharedManager].someProperty = @"asdf";
}
+ (id)sharedManager {
static FirstViewController *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
htmlの値をシングルトンに設定する必要があります。次の行
[FirstViewController sharedManager].someProperty = @"asdf";
このエラーが発生します
Propery 'someProperty' not found on object of type 'id'.
私はこのプロセス全体を何日も機能させるように努めてきました。洞察に感謝します。