所以我创建了一个简单UITableViewController的推到NavigationController. 我创建了一个initWithPList方法,该方法读取 aplist并将值存储到NSMutableDictionaryin a 中的items @propertyaclass中Settings。
在方法NSMutableDictionary中正确填充initWithStyle。但在viewDidLoad,是NSMutableDictionary items @property的。Settings NSObjectnil
我不确定我在做什么错任何想法????
这是一些代码:
显示 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;
}