だから私は私がUITableViewControllerにプッシュする単純なものを作成しましたNavigationController。initWithPListを読み取り、呼び出された内の にplist値を格納するメソッドを作成しました。NSMutableDictionaryitems @propertyclassSettings
NSMutableDictionaryがメソッドに正しく取り込まれますinitWithStyle。ただし、中古品のviewDidLoad場合はNSMutableDictionary items @property中古品Settings NSObjectですnil。
私は何を間違っているのか分かりません。
ここにいくつかのコードがあります:
表示中 ViewController:
TestViewController *settingsViewController = [[TestViewController alloc] initWithStyle:UITableViewStyleGrouped];
[[self navigationController] pushViewController:settingsViewController animated:YES]
の初期化 TestViewController:
- (id)initWithStyle:(UITableViewStyle)style{
if (self = [super initWithStyle:style]) {
// Init settings property here
settings = [[Settings alloc] initWithPList];
// settings.items has a count of 5 here....which is correct
}
return self;
}
viewDidLoad のために TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Check settings object here to see if it still has items
// settings.items is nil here for somereason??
NSLog(@"%i", [settings.items count]); // now it's nil here?
}
Settings NSObject:_
#import <Foundation/Foundation.h>
@interface Settings : NSObject {
NSMutableDictionary *items;
NSString *path;
}
@property(nonatomic, retain) NSMutableDictionary *items;
@property(nonatomic, retain) NSString *path;
-(id)initWithPList;
@end
のスニペット @implementation:
@synthesize items;
@synthesize path;
-(id) initWithPList {
path = [[self documentsDirectory]stringByAppendingPathComponent:@"Settings.plist"];
if(![[NSFileManager defaultManager]fileExistsAtPath:path])
{
[[NSFileManager defaultManager]copyItemAtPath:[[NSBundle mainBundle]pathForResource:@"Settings" ofType:@"plist"] toPath:path error:nil];
}
items = [NSMutableDictionary dictionaryWithContentsOfFile:path];
return self;
}