我有一个首选项视图,显示不同的表视图取决于哪个分段控件被点击。NSMutableArray,pList,Tableview泥泞和崩溃
我硬编码了一些NSMutableArrays测试基本原则:
prefsIssuesList = [[NSMutableArray alloc] init];
[prefsIssuesList addObject:@"Governance"];
[prefsIssuesList addObject:@"Innovation and technology"];
...etc
prefsIndustriesList = [[NSMutableArray alloc] init];
[prefsIndustriesList addObject:@"Aerospace and defence"];
... etc
prefsServicesList = [[NSMutableArray alloc] init];
[prefsServicesList addObject:@"Audit and assurance"];
...etc
currentArray = [[NSMutableArray alloc] init];
currentArray = self.prefsIssuesList;
然后重新装入currentArray的tableview中,加入UITableViewCellAccessoryCheckmark。 一切工作正常。
但现在我想要存储羯羊对号在plist文件中开启或关闭,并读取此回。
理想的情况下想这样
Root Dictionary
Issues Dictionary
Governance Number 1
Innovation and technology Number 0
etc
我有一个的plist至于工作了这一点
// Designate plist file
NSString *path = [[NSBundle mainBundle] pathForResource: @"issues" ofType:@"plist"];
// Load the file into a Dictionary
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.allNames= dict;
[dict release];
NSLog(@"Dict is %@", allNames); // All the data in the pList file
NSMutableArray *issueSection = [allNames objectForKey:@"Issues"];
NSLog(@"Issues is %@", issueSection); // The data is the Issues Section
NSString *issueVal = [issueSection objectForKey:@"Governance"];
NSLog(@"Governance is %@", issueVal); //The value of the Governance key
但我真正想要做的是通过问题词典循环并获得键/值对这样
key = cell.textLabel.text
value = UITableViewCellAccessoryCheckmark/UITableViewCellAccessoryNone
depending wether it's 1 or 0
我假设我仍然可以将三个NSMutableArrays中的一个指定给currentArray,就像我在硬编码版本中所做的一样,并使用currentArray重新加载tableview。
然后修改这个代码来构建的tableview
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [keys objectAtIndex:section];
NSArray *nameSection = [names objectForKey:key];
static NSString *CellIdentifier = @"Cell";
//UITableViewCell *cell = [self.prefsTableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
UITableViewCell *cell = [self.prefsTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell=[[[UITableViewCell alloc]
initWithFrame:CGRectZero
reuseIdentifier: CellIdentifier] autorelease];
}
cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
但我的大脑已经融化,我已经花了六小时左右今天的Plist,NSArrays,NSMutableDisctionaries,standardUserDefaults收效甚微读了。
我已经设法在UINavigationViews中使用UITableViews,使用SegmentedControls,下载异步XML,但是现在我终于被卡住了,或者两者兼而有之。在什么应该是相当简单的键/值对。
任何关心给我一些白痴指针?
PS,当我说的喜好观看我只是想说显示boolea一个UITableView的更好的方法n个选项(带有UITableViewCellAccessoryCheckmark),其中的XML位可显示在应用程序中的其他位置 – JulianB 2011-04-13 01:07:46
对不起,但我想知道你确切的问题在哪里?你能够正确存储数据吗?检索有问题吗? – Ravin 2011-04-13 03:31:00