将标记值发送到NSMutableArray objectAtIndex返回null

时间:2016-01-18 11:22:22

标签: ios tags nsmutablearray

我有一个产品详细信息列表作为NSMutableArray中的对象和产品图像列表作为图库,我需要在点击缩略图图像时加载完整图像。为此,我设置标签并在点击特定图像时获得精确的标签值。问题是我无法获取数组对象。我用手动数字测试,数组完美地返回对象。我在这里做错了什么?

标记设置代码:

for(int index=0; index < [self.sliderImages count]; index++) 
{ 
   UIImageView *imageView = [[UIImageView alloc]init]; 
   imageView.frame = CGRectMake(xOffset, 0, 100, scrollHeight);
   imageView.tag = index;
   Products *product = [self.sliderImages objectAtIndex:index];
   NSLog(@"product name %@",product.name);
   NSString *imageUrl = [NSString stringWithFormat:@"%@",product.imagePath];
}

点击手势识别器方法:

- (void) tapGesture:(id)sender 
{ 
    //handle Tap... 
    UIImageView *tmp = (UIImageView *)[sender view]; 
    int tm = (int)(tmp.tag); 
    NSLog(@"self.sliderImages%@",[self.sliderImages objectAtIndex:tm]);
    Products *product = [self.sliderImages objectAtIndex:tm];
    NSLog(@"product%@",product); 
    NSLog(@"product ges %@,, %@",product.name,product.imagePath);
    NSString *imageUrl = [NSString stringWithFormat:@"%@",product.imagePath];
    NSLog(@"full image path :: %@",imageUrl); 
    [self loadFullImage:tm];
}

1 个答案:

答案 0 :(得分:0)

你确定你的标签中没有nil吗? (int tm =(int)(tmp.tag))

您如何获得UIImageView的点击次数?你在使用手势识别器吗?

如果您使用的是手势识别器,请尝试使用手势识别器来接收相同的触摸和标签

  • (void)touch:(UIGestureRecognizer *)识别器