2015-11-16 58 views
0

即時通訊iOS開發新增功能。 這是一個小餐廳類型的應用程序。取決於餐廳,它將填充促銷活動。 我已經完成了迄今所有的工作,並獲得了在viewdidLoad方法中的數組提升列表。將dbmanager數據填充到UITableView

if (!dbmanager)dbmanager = [[DBManager alloc]init]; 
    array = [dbmanager getPromotions:[NSNumber numberWithInt:restId]]; 
    NSLog(@"%lu", (unsigned long)array.count); 

,並使用這個我能得到推廣詳情細節到日誌

for (PromotionTbl *order in array) { 
     NSLog(@"%@",order.promoName); 
    } 

我想填充在tableview中這些數據,所以我也做了的tableview正常implemantation和

加像這樣的細胞

cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"promoName"]; 

但即時通訊錯誤說

2015-11-16 11:20:35.825 Eatin[2858:1201859] -[PromotionTbl objectForKey:]: unrecognized selector sent to instance 0x7ffb507b3ab0 2015-11-16 11:20:35.834 Eatin[2858:1201859] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PromotionTbl objectForKey:]: unrecognized selector sent to instance 0x7ffb507b3ab0'

無我有objectForKey要做的事。

回答

1

用於顯示數據爲單元,這樣做:

PromotionTbl *order = [array objectAtIndex:indexPath.row]; 
cell.textLabel.text = order.promoName; 
cell.imageView.image = order.promotionImage; // If you want to display as a logo or thumbnail 

// If you have image URL and download image from it and then display 
[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:order.promotionImageURL]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 

    if (data) 
    { 
     cell.imageView.image = [[UIImage alloc] initWithData:data]; 
    } 
}]; 

如果你想顯示大圖像,然後,加UIImageViewUILabel到細胞和數據分配給它。或者您可以創建具有UIImageViewUILabel的自定義單元格。

+0

非常感謝。有效。 –

+0

,你能告訴我如何將圖像分配給該單元?在tableView中有Image作爲'order.promotionImage' –

+1

@Cade參見編輯答案 – VRAwesome

1

如果您確定您的數組包含PromotionTbl,則可以將該數組中的對象轉換爲PromotionTbl並訪問其值。

PromotionTbl *order = (PromotionTbl*)[array objectAtIndex:indexPath.row]; 
cell.textLabel.text = order.promoName; 
0

您需要獲取PromotionTbl的對象,然後才能訪問模型的屬性。

PromotionTbl promotionModel = (PromotionTbl*)array[indexPath.row]; 

if(promotionModel != nil) { 
    cell.textLabel.text = order.promoName; 
}