Wednesday, 15 January 2014

iphone - How to push a new view tapping programmatically added UiImageViews in a custom cell -



iphone - How to push a new view tapping programmatically added UiImageViews in a custom cell -

i want create when tap on image in uitableviewcell, pushes new view , displays uiimageview can manipulate (such pinching , expanding it).

currently, i'm using custom cell adds image cell programmatically:

for (int = 0; < [self.news.imgurl count]; i++) { uiimageview *image = [[uiimageview alloc] init]; [image setimagewithurl:[nsurl urlwithstring:[self.news.imgurl objectatindex:i]]]; [image setframe:cgrectmake(20, (labelsize.height + 25 + 14) + (i * 280), 280, 280)]; image.contentmode = uiviewcontentmodescaleaspectfit; image.tag = 101 + i; image.userinteractionenabled = yes; [self.contentview addsubview:image]; uitapgesturerecognizer *tap = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(handletap:)]; [tap setnumberoftapsrequired:1] [image addgesturerecognizer: tap]; }

this located in customcell.m file.

as seen in code above, utilize gesturerecognizer can observe taps of image using next code:

-(void) handletap:(uitapgesturerecognizer *)recognizer { if (recognizer.state == uigesturerecognizerstateended) { nslog(@"image tapped!", nil); } }

but have no thought how force new view within customcell.m file. there way force new view within customcell.m file or must explicitly masterviewcontroller?

this utilize case using delegate. define delegate protocol custom cell class. have table view controller set cell's delegate. protocol should have method tells delegate image tapped. cell , image parameters of delegate method.

in cell's handletap: method can check if delegate responds protocol method , if does, calls protocol on delegate, passing (the cell) , tapped image.

iphone objective-c xcode view push

No comments:

Post a Comment