2012-12-21 66 views
-1

我想要做以下事情:Plist中的NSDictionary和NSArray

一個plist文件,帶a-z和#表示數字或未知字符..所以27個數組。 我想將這27個數組存儲在字典中,一個plist文件。

它也有可能發生,那信是不是在字典陣列代表...

做我需要做27個陣列和檢查,如果存在的話,還是有更簡單的方法?

我想在實現代碼如下,以顯示他們..關鍵的所有值「一」表視圖,這樣....

任何想法的「一」節我怎麼可以節省時間和代碼?

感謝您的任何可能性,我可以嘗試

+0

「用A-Z和#爲數字或未知字符的plist文件..所以27個陣列。」你是如何計算27個數組的?另外,你不能使用NSCharacterSet嗎? –

+0

a-z數26和27將存儲數字和字符,可能是他有這個想法... –

回答

0

試試這個代碼在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]];