Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableView中解析来自网站的图像_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 在UITableView中解析来自网站的图像

Ios 在UITableView中解析来自网站的图像,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我正试图通过网站将图像解析到UITableViewCell中。我可以很容易地解析一个图像,但我正在尝试解析不同的多个图像。我对如何完成这项任务有一些想法,但我想知道执行这项任务最简单和最好的方法是什么。我怀疑这是否有帮助,但icon.jpg的命名类似于此1_icon、2_icon等。。。任何提示都将不胜感激 - (void)viewDidLoad { mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:

我正试图通过网站将图像解析到UITableViewCell中。我可以很容易地解析一个图像,但我正在尝试解析不同的多个图像。我对如何完成这项任务有一些想法,但我想知道执行这项任务最简单和最好的方法是什么。我怀疑这是否有帮助,但icon.jpg的命名类似于此1_icon、2_icon等。。。任何提示都将不胜感激

  - (void)viewDidLoad
  {

mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://example.com/uploads/1_icon.jpg"]];
myimage = [[UIImage alloc] initWithData:mydata];
_imageToDisplay.image=myimage;
self.tableview.delegate = self;
self.tableview.dataSource = self;




[super viewDidLoad];
// Do any additional setup after loading the view.
}

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString *CellIdentifier = @"Cell";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.accessoryView = [[UIImageView alloc] initWithImage:myimage];

return cell;
}
更新的.m

 _imagesArray = [[NSMutableArray alloc] init];
int numberOfIcons=30;

for(int i = 1; i <= numberOfIcons; i++){
    [_imagesArray addObject:[[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/uploads/%d_icon.jpg", i]]]]];
    NSLog(@"%d",numberOfIcons);

可以预加载数组中的所有图像,并在创建单元格时引用它们。这将阻止您在每次创建单元格时从web加载图像

在viewDidLoad中:

_imagesArray = [NSMutableArray alloc] init];
for(int i = 1; i <= numberOfIcons; i++){
  [array addObject:[[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/uploads/%d_icon.jpg", i]]]]];
}

对不起,我试图实现这个,但效果不太好。我可能误解了你的代码。我更新了我的代码,我想知道你是否能告诉我你的想法?非常感谢。-[\uu nsarray objectAtIndex:]:index 1 beyond bounds[0..0]“我将值切换到numberoficons=34和I=34以确保对象不是零。我相信是这一行导致了错误“cell.accessoryView=[[UIImageView alloc]initWithImage:[\u imagesArray objectAtIndex:indexath.row]];“尝试将numberOfRowsInSection的返回值设置为_imagesArray.count,并在填充数组后重新加载tableview数据。
_imagesArray = [NSMutableArray alloc] init];
for(int i = 1; i <= numberOfIcons; i++){
  [array addObject:[[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/uploads/%d_icon.jpg", i]]]]];
}
cell.accessoryView = [[UIImageView alloc] initWithImage:[_imagesArray objectAtIndex:indexPath.row]];