我是iOS开发的新手。这是小型餐厅类型的应用程序。根据餐厅的不同,它将在促销活动中占据一席之地。到目前为止,我已经完成了所有这些工作,并在viewdidLoad方法中获得了数组升级列表。
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和
添加这样的单元格
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的事情。
发布于 2015-11-16 06:06:31
要将数据显示到单元格中,请执行以下操作:
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];
}
}];如果要显示大图像,请将UIImageView和UILabel添加到单元格中,并向其分配数据。或者您可以创建具有UIImageView和UILabel的自定义单元格。
发布于 2015-11-16 06:11:02
如果确实确定数组包含PromotionTbl,则可以将数组中的对象强制转换为PromotionTbl并访问其值。
PromotionTbl *order = (PromotionTbl*)[array objectAtIndex:indexPath.row];
cell.textLabel.text = order.promoName;发布于 2015-11-18 05:09:04
您需要获得PromotionTbl的对象,然后可以访问模型的属性。
PromotionTbl promotionModel = (PromotionTbl*)array[indexPath.row];
if(promotionModel != nil) {
cell.textLabel.text = order.promoName;
}https://stackoverflow.com/questions/33729302
复制相似问题