使用.PLIST在Detailview中使用UIPickerView

时间:2011-06-12 10:12:32

标签: iphone uitableview plist uipickerview

我搜索了网络+ stackoverflow以寻求解决方案。

我有一个UITableView,其中包含.plist文件中的信息。 plist文件有孩子。像图像一样。

plist http://www.afbeeldingenuploaden.nl/uploads/648899Schermafbeelding%202011-06-12%20om%2009.50.28.png

当我转到DetailView时,它将显示视图中包含的UIPickerView信息。我想在最后一级的pickerview中显示来自孩子的信息。像图像一样。

plist1 http://www.afbeeldingenuploaden.nl/uploads/740501Schermafbeelding%202011-06-12%20om%2012.03.40.png

问题是我无法使用我的代码从UIPickerview中的plist到达最后一级。

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSDictionary *dictionary = [tableDataSource objectAtIndex:row];
    return [dictionary objectForKey:@"days"];
}

我在tableview中使用detailview来到达plist的最后一级。

NSString currentLevel

任何人都可以帮我解决这个问题,我被困住了。

3 个答案:

答案 0 :(得分:1)

当我读取plist时,它有一个字典数组,其中第一个字典作为第二个数组级别的值之一。基于此,您的方法应该是,

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSDictionary *dictionary = [tableDataSource objectAtIndex:row];

    return [[dictionary objectForKey:@"New item"] objectForKey:@"days"];
}

这适用于图像中的plist。但是,如果添加更多成员,则应遵循相同的结构。

答案 1 :(得分:0)

- (void)viewDidLoad {

[super viewDidLoad];

NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"Diyet.plist"];

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.data = tempDict;
[tempDict release];

NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];

self.tableDataSource = [data objectForKey:@"Bitki"];

pickerView.delegate = self;
pickerView.dataSource = self;

}

答案 2 :(得分:0)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

// Configure the cell.

cell.textLabel.text = [[tableDataSource objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.textLabel.numberOfLines = 2;
cell.textLabel.font = [UIFont boldSystemFontOfSize:16];

tableView.scrollEnabled = NO;

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


NSDictionary *dictionary = [tableDataSource objectAtIndex:indexPath.row];
NSArray *modelle = [dictionary objectForKey:@"DETAIL"];
if([modelle count] == 0) {

    DetailController *dvController = [[DetailController alloc] initWithNibName:@"DetailController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];


    dvController.names.text = [dictionary objectForKey:@"name"];

} else {

    BootViewController *rvController = [[BootViewController alloc] initWithNibName:@"BootViewController" bundle:[NSBundle mainBundle]];

    rvController.currentLevel += 1;

    rvController.currentTitle = [dictionary objectForKey:@"name"];

    [self.navigationController pushViewController:rvController animated:YES];

    rvController.tableDataSource = modelle;

    [rvController release];
}
}