无法在Plist中看到项目

时间:2012-02-19 23:20:17

标签: plist uipickerview

在互联网上进行了多次搜索后,我仍然无法将我的plist放入我的选择器视图中。这是我的plist:

<dict>
<key>root</key>
<dict>
    <key>roof</key>
    <array>
        <string>80</string>
        <string>100</string>
    </array>
</dict>

我的代码是:

- (void)viewDidLoad
NSString *path = [[NSBundle mainBundle] pathForResource:@"myPlist" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.myPlist = dict;


-(NSString *) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:myPlist.allKeys]; 
return [temp objectAtIndex:row];

结果只显示“根”......我做错了什么?任何想法都会受到最高的赞赏。

1 个答案:

答案 0 :(得分:0)

您是否实施了数据源代理?

 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

见:

When to use a plist, UIPickerView datasource help

另外作为旁注,为什么要创建可变数组temp?如果您不使用ARC,则不应该需要并且会泄漏。有任何问题让我知道。

相关问题