首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将dbmanager数据填充到UITableView中

将dbmanager数据填充到UITableView中
EN

Stack Overflow用户
提问于 2015-11-16 05:58:16
回答 3查看 34关注 0票数 0

我是iOS开发的新手。这是小型餐厅类型的应用程序。根据餐厅的不同,它将在促销活动中占据一席之地。到目前为止,我已经完成了所有这些工作,并在viewdidLoad方法中获得了数组升级列表。

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

使用此方法,我可以将促销详细信息输入日志

代码语言:javascript
复制
for (PromotionTbl *order in array) {
        NSLog(@"%@",order.promoName);
    }

我想在tableview中填充这些数据,所以我已经对tableview和

添加这样的单元格

代码语言:javascript
复制
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的事情。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-11-16 06:06:31

要将数据显示到单元格中,请执行以下操作:

代码语言:javascript
复制
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的自定义单元格。

票数 1
EN

Stack Overflow用户

发布于 2015-11-16 06:11:02

如果确实确定数组包含PromotionTbl,则可以将数组中的对象强制转换为PromotionTbl并访问其值。

代码语言:javascript
复制
PromotionTbl *order = (PromotionTbl*)[array objectAtIndex:indexPath.row];
cell.textLabel.text = order.promoName;
票数 1
EN

Stack Overflow用户

发布于 2015-11-18 05:09:04

您需要获得PromotionTbl的对象,然后可以访问模型的属性。

代码语言:javascript
复制
PromotionTbl promotionModel = (PromotionTbl*)array[indexPath.row];

if(promotionModel != nil) {
    cell.textLabel.text = order.promoName;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33729302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档