ios - UIButton isn't responding to my touches on collectionView cells? -
i'm creating collectionview , inside in every cell i'm creating few buttons horizontally buttons aren't responding target selector.
here code.
implementationview.h
-(ibaction)tagclicked:(uibutton*)sender;
in implementationview.m
-(void)configurescrapcell:(uicollectionviewcell*) cell forscrapdict:(scrapdictionary *)dict forindexpath:(nsindexpath*){ uiview *tagview = (uiview*)[cell viewwithtag:17]; uiview *layertagview = (uiview*)[cell viewwithtag:18]; cgfloat x = 0.0; if (layertagview) { [layertagview removefromsuperview]; } layertagview = [[uiview alloc] init]; layertagview.tag = 18; [tagview addsubview:layertagview]; if ([dict.sdtags count]>0) { int tagindex = 1; (nsstring *tag in dict.sdtags) { cgsize width = [tag sizewithfont:[uifont systemfontofsize:16]]; uibutton *scraptag = [[uibutton alloc]initwithframe:cgrectmake(x, 0,100, 30)]; [scraptag setbackgroundcolor:[uicolor greencolor]]; [scraptag.titlelabel setfont:[uifont systemfontofsize:14]]; // [scraptag setcontenthorizontalalignment:uicontrolcontenthorizontalalignmentleft]; if (brightness > 150) { [scraptag settitlecolor:[uicolor blackcolor] forstate:uicontrolstatenormal]; }else { [scraptag settitlecolor:[uicolor whitecolor] forstate:uicontrolstatenormal]; } [scraptag settitle:[nsstring stringwithformat:@" #%@",tag] forstate:uicontrolstatenormal]; // [scraptag sizetofit]; [scraptag setuserinteractionenabled:yes]; tagindex++; nsstring *tagstring = @""; tagstring = [tagstring stringbyappendingstring:tag]; if ([tagstring length]>32 || tagindex>4) { break; } [scraptag addtarget:self action:@selector(tagclicked:) forcontrolevents:uicontroleventtouchupinside]; [layertagview addsubview:scraptag]; nslog(@"%f",scraptag.frame.size.width); // scraptag.frame = cgrectmake(x, scraptag.frame.origin.y, tagview.frame.size.width, 30); x += scraptag.frame.size.width +2; } } [tagview setbackgroundcolor:[uicolor colorwithred:red/255.0f green:green/255.0f blue:blue/255.0f alpha:0.5]]; [layertagview setbackgroundcolor:[uicolor colorwithred:red/255.0f green:green/255.0f blue:blue/255.0f alpha:0.5]];
now in different class i'm defining action of these button clicked. implementationview class acting delegate newclass.
newclass.h
#import implementationview.h @interface newclass : implementationview
newclass.m
-(ibaction)tagclicked:(uibutton *)sender { [[[uialertview alloc]initwithtitle:@"lol" message:[nsstring stringwithformat:@"%@",sender.titlelabel.text] delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]show ]; nslog(@"testing tag clicked"); }
let me know if need other make question clear. appreciated. in advance.
your buttons not on layertagview bounds. need set layertagview frame/size. in code size of layertagview (0,0). check suggestions can set maskstobounds yes or change background color layertagview blue or other color.
tagview.layer.maskstobounds = yes; layertagview.layer.maskstobounds = yes;
Comments
Post a Comment