【问题标题】:UIPickerView in Detailview with .PLIST带有 .PLIST 的 Detailview 中的 UIPickerView
【发布时间】:2011-06-12 10:12:32
【问题描述】:

我已经在 web + 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

谁能帮帮我,我卡住了。

【问题讨论】:

    标签: iphone uitableview plist uipickerview


    【解决方案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。但是,如果添加更多成员,它们应该遵循相同的结构。

    【讨论】:

    • 你是怎么得到tableDataSource的?
    • 我作为与此主题相关的答案发布。
    • 你也可以发布cellForRowAtIndexPath:方法。我只需要知道您是如何使用tableDataSource 填充行的。
    • 我还发布了 didSelectRowAtIndexPath: 方法的代码。在那里,您可以看到我如何在 Detailview 中到达 .plist 的最后一级以获取字符串。
    【解决方案2】:
    - (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;
    
    }
    

    【讨论】:

      【解决方案3】:
      - (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];
      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-09
        相关资源
        最近更新 更多