【发布时间】:2014-01-31 00:48:38
【问题描述】:
我有一个 plist,带有键值,键是字符串,值也是字符串。 我不希望 uitableview 部分标题的输出根据 plist 中的键 .也就是说,我的意思是 key1-应该是 section-1 的标题,key-2 应该是 section-2 的标题,很快。 这是我的示例 plist
<?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;
}
到目前为止,我得到了这个
我需要这个输出 1-设置 2-通知 3-信息
我很感激的任何帮助,可能是我盯着屏幕看了很长时间,我的大脑错过了一些东西,:P
【问题讨论】:
标签: ios iphone objective-c uitableview