我的問題與this one類似,但我感覺不同,所以我需要在這裏提出問題。iOS - 在'NSArray'類型的對象上找不到屬性「name」
我正在創建我的第一個iOS應用程序,一個基本的主 - 細節應用程序,並使用JSONModel來提取API,但我認爲在這種情況下並不多。我有一個UITableView,其中每一行代表一個拳擊手,每個拳擊手都有一個名稱,重量級別,記錄等,這一切都很好。我遇到問題的地方是在各個詳細信息頁面上顯示該數據。主要是我無法弄清楚我應該如何在segue中傳遞數據,我知道我想使用該行來傳遞關聯的boxer對象,但似乎無法找出正確的方法。在我的代碼中,我有NSArray,但也嘗試過NSMutableArray和NSObject,每個都有相同的錯誤:在'NSW whatever'類型的對象上找不到屬性'name'。任何幫助,將不勝感激。謝謝。
BoxerMasterViewController.m
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Boxer* boxerDetails = _feed.boxers[indexPath.row];
BoxerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BoxerCell" forIndexPath:indexPath];
cell.boxerNameLabel.text = [NSString stringWithFormat:@"%@", boxerDetails.name];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showBoxerDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSArray *object = _feed.boxers[indexPath.row];
[[segue destinationViewController] setBoxerDetailItem:object];
}
}
BoxerDetailViewController.h
#import <UIKit/UIKit.h>
@interface BoxerDetailViewController : UIViewController
@property (strong, nonatomic) NSArray *boxerDetailItem;
@property (weak, nonatomic) IBOutlet UILabel *boxerName;
@end
BoxerDetailViewController.m
self.boxerName.text = [self.boxerDetailItem.name];
eugh,你是對的,那會教我跑遍百家教程,看起來每個代碼都需要一些代碼。我要解決我的問題,如果沒有錯誤將其標記爲正確的答案。謝謝! –
這是你沒有列出的代碼的一部分,所以我沒有建議你在那裏。 – Putz1103