2016-01-12 92 views
-1

我正在構建一個應用程序,需要在tableView中顯示某些信息,從.plist文件獲取所述信息。在plist文件中,有一個根文件,它是一個數組。每個數組項(這是所有詞典),有4個項目在他們裏面:如何在我的tableView中顯示這些信息?

  • 名稱(字符串)
  • 成分(陣列)
  • 步驟(陣列)
  • 評論

我需要讓tableView只有一個標籤,顯示「Name」字符串中的文本。其他項目將在稍後使用。

我該怎麼做?如果有必要,我會很樂意提供更多信息。

在此先感謝。在

方法 地方代碼:

回答

3

你可以在你tableview設置從plistlabel價值- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"Exercise" ofType:@"plist"]; 
exerciseArray = [NSArray arrayWithContentsOfFile:plistPath]; 

label.text =[[exerciseArray objectAtIndex:indexPath.row]objectForKey:@"Name"]; 
-1

首先,你需要從一個NSBundle您的plist文件的路徑。然後將這些元素存儲在一個數組中,並使用indexpath.row中的數組元素填充標籤以獲取關鍵字「name」。希望這可以幫助。

NSString *path = [[NSBundle mainBundle]pathForResource:@"Menu" ofType:@"plist"]; 
NSMutableArray *menuArray = [NSMutableArray arrayWithContentsOfFile : path]; 
nameLabel.text = [[menuArray objectAtIndex:indexPath.row]objectForKey: @"name"]; 
0

根據您的要求定製UITableViewCell和設計類。然後從plist文件中取數據。以CellForRowAtIndexPath方法將數據分配給CustomTableViewCell

相關問題