【问题标题】:Can´t see items in Plist在 Plist 中看不到项目
【发布时间】:2012-02-19 23:20:16
【问题描述】:

在互联网上进行了多次搜索后,我仍然无法将我的 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];

结果只显示“root”....我做错了什么?任何想法将不胜感激。

【问题讨论】:

    标签: plist uipickerview


    【解决方案1】:

    您是否实现了数据源委托?

     - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    

    看这个:

    When to use a plist, UIPickerView datasource help

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

    【讨论】:

    • 你好 daltoniam,谢谢你的帮助..我已经有了解决方案。问题是 plist 最初是字典而不是数组,所以在我的 .h 文件中,我使用了 NSDictionary 变量( NSDicionary *myplist),然后在我的 .m 中,我使用 NSDicitionary 使用了我的选择器视图方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-22
    • 1970-01-01
    相关资源
    最近更新 更多