2012-02-19 60 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

相關問題