먼저 모든 도움을 주셔서 감사합니다.AFNetworking UIGestureRecognizer setCompletionBlockWithSuccess
AFNetworking을 사용하여 여러 이미지를 다운로드하려고하는데 문제는 블록 성공 부분에 제스처 인식기를 추가하려고 할 때 오류가 발생한다는 것입니다.
이것은 내 코드입니다.
- (void)loadPictures {
NSArray *listItems = [[_dictForData objectForKey:@"imgs"] componentsSeparatedByString:ITEM_SEPARATOR];
NSLog(@" == Num Images %d", [listItems count]-1);
NSMutableArray *imgNames= [[NSMutableArray alloc] init];
for(int i=0;i<[listItems count]-1;i++)
{
NSString *nameImage = [listItems[i] componentsSeparatedByString:TAG_SEPARATOR][1];
NSLog(@" == Name Image %@", nameImage);
[imgNames addObject: nameImage];
NSLog(@"== %@", [imgNames objectAtIndex:i]);
}
// Setup the array of UIImageViews
NSMutableArray *imgArray = [[NSMutableArray alloc] init];
for(NSString *name in imgNames) {
NSString *string = [NSString stringWithFormat:@"%@%@%@%@%@", SERVER, URL_FILES,[_dictForData objectForKey:@"id"],URL_IMAGES_HI,name];
NSURL *url = [NSURL URLWithString:string];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
UIImageView *tempImageView;
tempImageView = [[UIImageView alloc] init];
tempImageView.contentMode = UIViewContentModeScaleAspectFit;
tempImageView.image = responseObject;
[imgArray addObject:tempImageView];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[tempImageView setUserInteractionEnabled:YES];
[tempImageView addGestureRecognizer:singleTap];
if ([imgArray count] == [listItems count]-1) {
//CGSize pageSize = self.scrollView.frame.size; // scrollView is an IBOutlet for our UIScrollView
NSUInteger page = 0;
NSUInteger widthPicture = 100;
NSUInteger heightPicture = 100;
for(UIView *view in imgArray) {
[self.scrollView addSubview:view];
// This is the important line
//view.frame = CGRectMake(pageSize.width * page++ + 10, 0, pageSize.width - 20, pageSize.height);
view.frame = CGRectMake(widthPicture * page++, 0, widthPicture - 5, heightPicture);
// We're making use of the scrollView's frame size (pageSize) so we need to;
// +10 to left offset of image pos (1/2 the gap)
// -20 for UIImageView's width (to leave 10 gap at left and right)
}
//self.scrollView.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height);
self.scrollView.contentSize = CGSizeMake((widthPicture + 5) * [imgArray count], 100);
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Image error: %@", error);
}];
[requestOperation start];
}
}
-(void)tapDetected{
NSLog(@"single Tap on imageview");
}
EDIT :
오류가 EXC_BAD_ACCESS (코드 = 1, 어드레스 = 0x7000000C)이고 i는 이미지 뷰를 탭.
생성 된 이미지를 탭하고 이미지 뷰에 단일 탭을 표시해야합니다.
내가 뭘 잘못하고있어? 또는 어떻게 그것을 해결할 수 있습니까?. imgArray [imgArray addObject:tempImageView];
내 Inglish
을 제거 코드와 완전히
작업을 테스트 오류 메시지를 제공하시기 바랍니다.! –
방금 감사를 편집했습니다. –
UIImageView를 임의의 뷰에 추가하지 않습니다 .. !!! [myAwesomeView addSubview : tempImageView]; –