Tuesday 15 March 2011

ios - AFNetworking UIGestureRecognizer inside setCompletionBlockWithSuccess -



ios - AFNetworking UIGestureRecognizer inside setCompletionBlockWithSuccess -

first of help.

i'm trying download several images afnetworking, question when seek add together gesture recognizer within block success part , after finished error.

this code.

- (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 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 iboutlet our uiscrollview nsuinteger page = 0; nsuinteger widthpicture = 100; nsuinteger heightpicture = 100; for(uiview *view in imgarray) { [self.scrollview addsubview:view]; // of import 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 utilize of scrollview's frame size (pagesize) need to; // +10 left offset of image pos (1/2 gap) // -20 uiimageview's width (to leave 10 gap @ left , 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:

the error exc_bad_access (code=1, address=0x7000000c) when tap imageview.

i need tap on images created , show single tap on imageview.

what i'm doing wrong? or how solve it?.

thanks in advance , sorry inglish

instead of adding uiimageview imgarray [imgarray addobject:tempimageview]; straight add together [self.scrollview addsubview:tempimageview]; comment loop. understand using loop cgrectmake. still tested code , working removed line if ([imgarray count] == [listitems count]-1) {

uiimageview *tempimageview; tempimageview = [[uiimageview alloc] init]; tempimageview.contentmode = uiviewcontentmodescaleaspectfit; tempimageview.image = responseobject; [imgarray addobject:tempimageview]; [self.view addsubview:tempimageview]; uitapgesturerecognizer *singletap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapdetected)]; singletap.numberoftapsrequired = 1; [tempimageview setuserinteractionenabled:yes]; [tempimageview addgesturerecognizer:singletap];

ios objective-c-blocks afnetworking-2 uitapgesturerecognizer

No comments:

Post a Comment