2011-10-25 50 views
1

我是iPhone新手,並且從這裏獲得了很大的成功,因此我希望能夠直接獲得幫助。我正在將數據讀入plist的tableview中。該應用程序工作正常,但我編譯時得到2個警告。我知道爲什麼我會得到這些錯誤,但我一直沒有解決問題。雖然這個應用程序的作品,我真的想有效解決警告。當我嘗試將NSDictionary更改爲NSArray時,警告消失,但表不再填充。從nsdictionary分配給nsarray的不兼容指針類型

任何幫助將不勝感激。

工作人員和數據在委託.h文件中定義爲NSArray。警告顯示在下面的代理.m文件中。

我的代表有以下幾點:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    // Add the tab bar controller's current view as a subview of the window 

NSString *Path = [[NSBundle mainBundle] bundlePath]; 
NSString *DataPath = [Path stringByAppendingPathComponent:@"Data.plist"]; 
NSString *SPath = [[NSBundle mainBundle] bundlePath]; 
NSString *StaffPath = [SPath stringByAppendingPathComponent:@"Staff.plist"]; 

NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath]; 
**self.data = tempDict;** 
[tempDict release]; 


    NSDictionary *staffDict = [[NSDictionary alloc]initWithContentsOfFile:StaffPath]; 
    **self.staff = staffDict;** 
    [staffDict release]; 

在我的工作人員的ViewController我有以下幾點:在你的代碼

if(CurrentLevel == 0) { 

     //Initialize our table data source 
     NSArray *staffDict = [[NSArray alloc] init]; 
     self.tableDataSource = staffDict; 
     [staffDict release]; 


     Midwest_DigestiveAppDelegate *AppDelegate = (Midwest_DigestiveAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"];  
} 
else 
    self.navigationItem.title = CurrentTitle; 
+0

你解決了這個問題嗎? @Corey Brown我遇到同樣的問題 –

回答

0

一切都表明,員工和數據屬性的NSDictionary實例。您將它們初始化爲字典對象,然後將它們作爲字典對象引用。那麼爲什麼你將它們聲明爲NSArray對象呢?

你應該改變它們是如何聲明的,所以它們在你的頭文件中是NSDictionary而不是NSArray。在我看來,這是刪除警告最合乎邏輯的方法。

這應該仍然工作,假設你的「staff」NSDictionary的內容有一個名爲「行」的鍵值爲NSArray的鍵。你有一個空的NSArray初始化self.tableDataSource的代碼似乎是多餘的,因爲你立即覆蓋在你的代碼與

self.tableDataSource = [AppDelegate.staff valueForKey:@"Rows"]; 

線值

+0

非常感謝。我之前嘗試過這種方法,而桌子卻是空的,但這次它工作正常。 –

1

NSArray持有的項目,其中的一個一個維列表NSDictionary將鍵映射到值。

陣列:

[A,B,C]

詞典:

{@ 「一」= @ 「第一項」,@ 「B」= @「第二項「}

你能申報數據爲NSDictionary *data;和填充它爲data = [[NSDictionary alloc] initWithContentsOfFile:DataPath];

然後在字典中訪問值[data valueForKey:@"key"]

相關問題