2012-02-19 57 views
1

在互联网上进行了很多搜索之后,我仍然遇到了将我的plist放在我的选择器视图中的问题。这是我的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]; 

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

回答

0

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

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 

看到这个:

When to use a plist, UIPickerView datasource help

另外,作为一个侧面说明,你为什么要创建可变数组温度?如果您不使用ARC,则不应该需要并且会泄漏。任何问题都让我知道。

+0

hello daltoniam,感谢您的帮助..我已经有了解决方案。问题是,plist最初是一个字典,而不是一个数组,所以在我的.h文件中,我使用了一个NSDictionary变量(NSDicionary * myplist),然后在我的.m上使用NSDicitionary工作了我的选择器视图方法。 – Japa 2012-03-18 23:29:29

相关问题