0
我有一個plist,鍵值,鍵是字符串,值也是字符串。 我不希望根據plist 中的鍵將uitableview部分標題的輸出顯示出來。這就是說,我的意思是key1-應該是第1部分的標題,key-2應該是第2部分的標題並且很快。 這裏是我的榜樣的plist如何安排基於plist鍵的UITableView部分標題?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Settings</key>
<array>
<string>one-one</string>
<string>one-two</string>
</array>
<key>Notifications</key>
<array>
<string>two-one</string>
<string>two-two</string>
</array>
<key>Info</key>
<array>
<string>three_one</string>
<string>three_two</string>
<string>three_three</string>
</array>
</dict>
</plist>
這裏是我試過的viewDidLoad
_
data = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"settings" ofType:@"plist"]];
NSArray *first = [_data valueForKey:@"Settings"];
NSArray *second = [_data valueForKey:@"Notifications"];
NSArray *third = [_data valueForKey:@"Info"];
NSDictionary *temp =[[NSDictionary alloc]
initWithObjectsAndKeys:first, @"Settings",second, @"Notificatitons",third, @"Info", nil];
_data = temp;
重新排列碼這是表格數據源配置
#pragma mark - data source
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [_data count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[_data allKeys] objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
NSString *continent = [self tableView:_testTable titleForHeaderInSection:section];
return [[_data valueForKey:continent] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *rekebishaCell = @"RekebishaCell";
NSString *continent = [self tableView:_testTable titleForHeaderInSection:indexPath.section];
NSString *sub_settings = [[_data valueForKey:continent] objectAtIndex:indexPath.row];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: rekebishaCell];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
reuseIdentifier:rekebishaCell];
}
// config cell ui
//cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.text = sub_settings;
return cell;
}
到目前爲止我m如果這個
這個我需要這個輸出 1設置 2-通知 3-信息
任何幫助,我很感激,可我一直在盯着我的屏幕相當長的一段時間,我的大腦失去了一些東西, :P
...這是我面對,我會考慮重組我的數據結構基金,我是NSArray的是很長的路要走,感謝小費的確切問題,但讓我們等待可能被某人做了這個b4。 – abdimuna
我不認爲有人用你描述的方式使用了一個'NSDictionary'。我相當肯定你現在唯一的解決方案就是使用除字典之外的其他東西,或者將記錄拉出來,按照你想要的方式對它們進行排序,然後*將它們用作表格的數據源。 – Aaron
...亞倫我只是想維護plist中按鍵的順序。因爲NSDictionary不保持鍵的順序,這就是我面對的問題!,我期待這篇文章可能會導致我走向正確的道路! http://www.cocoawithlove.com/2008/12/ordereddictionary-subclassing-cocoa.html – abdimuna