Ios 从数据库获取url并将其作为UITableView的图像放置

Ios 从数据库获取url并将其作为UITableView的图像放置,ios,iphone,objective-c,uitableview,Ios,Iphone,Objective C,Uitableview,全部, 我需要为UITableView分配一张图片。每行有不同的图片。每一行的数据来自一个数据库,该数据库中的一行有一个ID,另一个数据库中的ID是链接的,并且在该表中有一个图像的URL 因此,在cellforRowAtIndexPath中,我们有: NSDictionary*postValues=@{@“myParam”:apt[@“barID”]} 这就从表中引入了url,它是JSON,我删除了所有标记,得到了一个字符串,它只是“这是简单的一点”。 我使用SBWebImage将图像放在uit

全部,

我需要为UITableView分配一张图片。每行有不同的图片。每一行的数据来自一个数据库,该数据库中的一行有一个ID,另一个数据库中的ID是链接的,并且在该表中有一个图像的URL

因此,在cellforRowAtIndexPath中,我们有: NSDictionary*postValues=@{@“myParam”:apt[@“barID”]}

这就从表中引入了url,它是JSON,我删除了所有标记,得到了一个字符串,它只是“这是简单的一点”。
我使用SBWebImage将图像放在uitableview异步中,这也很好。在url的每一行上放置图像的最佳方式是什么。使用SWITCH语句是否最好?最好是使用URL数组,然后显示它们。是否最好从cellforIndexRowPath移动数据库连接?有人能给我一些建议吗

首先,为uitableview创建一个自定义视图单元格。然后将子视图(如图像、标签)添加到自定义单元格中。将数据从数据库获取到图像数组中,ID数组在CellForRowatinex的tableview委托方法中使用代码

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {静态NSString*CellIdentifier=@“Cell”; 如果(tableView==myTableView){ FirstViewCustomCell*单元格=(FirstViewCustomCell*)[myTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 如果(单元格==nil) { [[NSBundle mainBundle]loadNibNamed:@“FirstViewCustomCell”所有者:self 选项:无]; 单元格=自定义单元格; customCell=nil; }
[单元格设置选择样式:UITableViewCellSelectionStyleNone]; //从数据库中获取数据。 cell.customimage.image=[ImageSarrObjectatindex:indexath.row]; cell.textlab.text=[arrayofID objectatIndex:indexath.row];
}

分别解析数据..在方法中,然后

将图像存储在数组中..如您所需的前三个图像

如果您正在将图像的URL保存在对象中,然后保存到数组中,请使用下面的代码

    for(int i=0;i<3;i++)
    {
    ImagesObject *Obj=[imagesArray objectAtIndex:i];

            [cell.userProfilePicImage setImageWithURL:[NSURL URLWithString:Obj.imageURLString]
                                     placeholderImage:[UIImage imageNamed:@"greybox40.png"]
                                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
             {
                 if (!error && image)
                 {

                 }
             }];
        }

        (or) if you are not saving in an object then use below code.

for(int i=0;i<3;i++)
    {

        NSString *imageURLString=[imagesArray objectAtIndex:i];

                [cell.userProfilePicImage setImageWithURL:[NSURL URLWithString:imageURLString]
                                         placeholderImage:[UIImage imageNamed:@"greybox40.png"]
                                                completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
                 {
                     if (!error && image)
                     {

                     }
                 }];
}

用于(int i=0;我只想要UITableView中的前三名。谢谢你提供的信息,但你失去了我!!是的,我知道了,所以在某个地方创建一个包含方法中所有图像URL的数组。调用该方法填充数组。然后将上述代码放入viewforcellrowsatindex。@user3229170是的……如果你只想在数组中存储图像URL,请使用第二个for循环代码,如果您想使用imageurl存储任何内容,最好使用object并将所有内容存储在一个对象中,然后再存储到数组中。使用first for循环..我正在尝试从我的SQL块生成一个方法,现在允许返回语句,有什么想法吗?
    for(int i=0;i<3;i++)
    {
    ImagesObject *Obj=[imagesArray objectAtIndex:i];

            [cell.userProfilePicImage setImageWithURL:[NSURL URLWithString:Obj.imageURLString]
                                     placeholderImage:[UIImage imageNamed:@"greybox40.png"]
                                            completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
             {
                 if (!error && image)
                 {

                 }
             }];
        }

        (or) if you are not saving in an object then use below code.

for(int i=0;i<3;i++)
    {

        NSString *imageURLString=[imagesArray objectAtIndex:i];

                [cell.userProfilePicImage setImageWithURL:[NSURL URLWithString:imageURLString]
                                         placeholderImage:[UIImage imageNamed:@"greybox40.png"]
                                                completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
                 {
                     if (!error && image)
                     {

                     }
                 }];
}