簡體   English   中英

需要幫助從NSDictionary設置單元格的TextLabel

[英]Need Help Setting Cell's TextLabel From NSDictionary

所以我有一個NSDictionary,里面有4個對象。 每個對象都具有2個屬性,即namedate

我可以通過記錄列出所有數據。

我假設您的示例代碼在此方法內:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

如果沒有,那是您的第一個問題。

現在,您可能會依次設置每個單元格,使每個標題一一顯示,直到到達列表的末尾。 所有單元格都具有相同的標題,因為它們都具有列表中的最后一個標題。

您應該刪除for循環並改用它:

NSDictionary *object = [objects objectAtIndex:[indexPath row]];
NSString *title = [object objectForKey:@"title"];
NSString *date = [object objectForKey:@"publishedDate"];
cell.textLabel.text  = title;
cell.detailTextLabel.text  = date;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM