ios - UIButton action selector -
i have following code:
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { uiimage * search = [uiimage imagenamed: @"search.png"]; uiimageview * s = [[uiimageview alloc] initwithimage: search]; s.frame = cgrectmake(15, 14, search.size.width, search.size.height); uiimage * simg = [uiimage imagenamed: @"m_search_back.png"]; uiimage * img = [uiimage imagenamed: @"m_top.png"]; cgrect searchbarframe = cgrectmake(0, 0, self.tableview.frame.size.width, 45.0); self.searchbar = [[uisearchbar alloc] initwithframe:searchbarframe]; self.searchbar.backgroundimage = simg; [self.searchbar setsearchfieldbackgroundimage: simg forstate:uicontrolstatenormal]; self.searchbar.delegate = self; [self.searchbar addsubview: s]; uitextfield *searchfield = [self.searchbar valueforkey:@"_searchfield"]; // change search bar text color searchfield.textcolor = [uicolor colorwithred: 178.0/255 green:178/255.0 blue:178/255.0 alpha:1.0]; searchfield.font = [uifont fontwithname: @"helveticaneue-light" size: 16.0f]; // change search bar placeholder text color [searchfield setvalue:[uicolor whitecolor] forkeypath:@"_placeholderlabel.textcolor"]; [self.searchbar setplaceholder:@"search investors, startups, founders, etc"]; uiimageview * top = [[uiimageview alloc] initwithimage: img]; top.frame = cgrectmake(0, self.searchbar.frame.size.height + 1, 800, img.size.height); uilabel * topl = [[uilabel alloc] initwithframe: cgrectmake(30, 10, 800, img.size.height - 30)]; topl.text = @"connect with\nfounders , investors"; topl.numberoflines = 0; topl.backgroundcolor = [uicolor clearcolor]; topl.textcolor = [uicolor whitecolor]; topl.textalignment = nstextalignmentcenter; [topl setfont: [uifont fontwithname: @"helveticaneue-bold" size: 17.0f]]; [topl sizetofit]; [top addsubview: topl]; uiimage * loginbtn = [uiimage imagenamed: @"loginbtn.png"]; uiimage * sep1 = [uiimage imagenamed: @"m_sep1.png"]; uibutton * login = [[uibutton alloc] initwithframe: cgrectmake(30, 70, loginbtn.size.width, loginbtn.size.height)]; [login.titlelabel setfont: [uifont fontwithname: @"helveticaneue-medium" size: 16.0f] ]; [login settitle:@"login" forstate: uicontrolstatenormal]; [login addtarget: self action:@selector(loginuser:) forcontrolevents:uicontroleventtouchupinside]; [login setbackgroundimage: loginbtn forstate: uicontrolstatenormal]; [top addsubview: login]; uiimage * greenbtn = [uiimage imagenamed: @"greenbtn.png"]; uibutton * green = [[uibutton alloc] initwithframe: cgrectmake(loginbtn.size.width + 50, 70, greenbtn.size.width, greenbtn.size.height)]; [green settitle:@"register" forstate: uicontrolstatenormal]; [green.titlelabel setfont: [uifont fontwithname: @"helveticaneue-medium" size: 16.0f] ]; [green setbackgroundimage: greenbtn forstate: uicontrolstatenormal]; [green addtarget:self action:@selector(registeruser:) forcontrolevents:uicontroleventtouchupinside]; [top addsubview: green]; uiimageview * sep2 = [[uiimageview alloc] initwithimage: sep1]; sep2.frame = cgrectmake(0, top.frame.origin.y + top.frame.size.height - 2, top.frame.size.width, 1); uiimage * sep5img = [uiimage imagenamed: @"m_sep5.png"]; uiimageview * sep5 = [[uiimageview alloc] initwithimage: sep5img]; sep5.frame = cgrectmake(0, self.searchbar.frame.origin.y + self.searchbar.frame.size.height, self.searchbar.frame.size.width, sep5img.size.height); uiview * toph = [[uiview alloc] initwithframe: cgrectmake(0, 0, 800, simg.size.height + top.frame.size.height + 2)]; [toph addsubview: self.searchbar]; [toph addsubview: sep5]; [toph addsubview: top]; [toph addsubview: sep2]; return toph; }
unfortunately, tried adding action uibutton "login" not working. loginuser function not being called. can do? setting action on uibutton correctly?
thanks.
i believe imageviews have userinteractionenabled set no default. try adding:
top.userinteractionenabled = yes;
Comments
Post a Comment