試試這個代碼在plist文件
寫入數據
NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSMutableArray *arr = [NSMutableArray new];
for (char value = 'a'; value<='z'; value++) {
[arr addObject:[NSString stringWithFormat:@"%c",value]];
}
NSDictionary *dict = [NSDictionary dictionaryWithObject:arr forKey:@"alphabet"];
[dict writeToFile:filePath atomically:YES]
集numberOfSectionsInTableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return [[dict objectForKey:@"alphabet"]count];
}
集numberOfRowsInSection
在的cellForRowAtIndexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
組單元格文本
[[cell textLabel] setText:[[dict objectForKey:@"alphabet"]objectAtIndex:indexPath.section]];
「用A-Z和#爲數字或未知字符的plist文件..所以27個陣列。」你是如何計算27個數組的?另外,你不能使用NSCharacterSet嗎? –
a-z數26和27將存儲數字和字符,可能是他有這個想法... –