Reputation: 1876
im new to iOS development. This is small Restaurant type app. depending on restaurant it will populate the promotions. i have done all that so far and getting list of promotion to array in viewdidLoad method.
if (!dbmanager)dbmanager = [[DBManager alloc]init];
array = [dbmanager getPromotions:[NSNumber numberWithInt:restId]];
NSLog(@"%lu", (unsigned long)array.count);
and using this i can get the details of Promotion Details into Log
for (PromotionTbl *order in array) {
NSLog(@"%@",order.promoName);
}
i want to populate these data in tableview so i have done the normal implemantation for tableview and
add cell like this
cell.textLabel.text = [[array objectAtIndex:indexPath.row]objectForKey:@"promoName"];
but im getting error saying
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'
I have done without objectForKey
as well.
Upvotes: 0
Views: 41
Reputation: 121
You need to get object of PromotionTbl and then you can access the properties of the model.
PromotionTbl promotionModel = (PromotionTbl*)array[indexPath.row];
if(promotionModel != nil) {
cell.textLabel.text = order.promoName;
}
Upvotes: 0
Reputation: 4803
For displaying data into cell, do like this :
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];
}
}];
If you want to display large image then, add UIImageView
and UILabel
to cell and assign data to it. Or you can create custom cell having UIImageView
and UILabel
.
Upvotes: 1
Reputation: 1379
if you really sure that your array contain PromotionTbl, you can cast the object in array to PromotionTbl and access its value.
PromotionTbl *order = (PromotionTbl*)[array objectAtIndex:indexPath.row];
cell.textLabel.text = order.promoName;
Upvotes: 1