objective c - action messages not being passed -
im using custom cells tableview. i've created xib cell design , hooked elements uitableviewcell subclass named 'cell'. there's no file's owner xib. custom cell has 3 label views. 1 in left corner, 1 middle, , other 1 in right corner. out of these, don't want left , right cornered labels actionable, i.e these should not trigger action on beingness tapped. middle label should actionable i.e perform relevant action on tapping.
i have registered xib bundle uitableviewcontroller subclass in 'viewdidload' method. code snippet:-
cell.h
#import <uikit/uikit.h> @interface cell : uitableviewcell @property (weak, nonatomic) iboutlet uilabel *authorlabel; @property (weak, nonatomic) iboutlet uilabel *titlelabel; @property (weak, nonatomic) iboutlet uilabel *categorylabel; - (ibaction)authortapped:(id)sender; //not actionable - (ibaction)categorytapped:(id)sender;//not actionable @end
cell.m
#import "cell.h" @implementation cell - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { nslog(@"cell init"); self = [super initwithstyle:uitableviewcellstylesubtitle reuseidentifier:reuseidentifier]; if (self) { // initialization code } homecoming self; } - (ibaction)authortapped:(id)sender { //do nil on tapping left label nslog(@"author tapped"); return; } - (ibaction)categorytapped:(id)sender {//do nil on tapping right label nslog(@"category tapped"); return; } @end
listviewcontroller.h
#import <foundation/foundation.h> @interface listviewcontroller : uitableviewcontroller
listviewcontroller.m
#import "listviewcontroller.h" #import "cell.h" @implementation listviewcontroller - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithstyle:style]; if (self) { [self fetchentries]; [[self navigationitem] settitle:@"list"]; nslog(@"%@",self.view); } homecoming self; } -(void) viewdidload{ [super viewdidload]; nslog(@"registering xib custom cell"); uinib *nib = [uinib nibwithnibname:@"cell" bundle:nil]; [[self tableview] registernib:nib forcellreuseidentifier:@"cell"]; } - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // force web view controller onto navigation stack - implicitly // creates web view controller's view first time through [[self navigationcontroller] pushviewcontroller:webviewcontroller animated:yes]; // grab selected item rssitem *entry = [[channel items] objectatindex:[indexpath row]]; // build url link string of item nsurl *url = [nsurl urlwithstring:[entry link]]; // build request object url nsurlrequest *req = [nsurlrequest requestwithurl:url]; // load request web view [[webviewcontroller webview] loadrequest:req]; // set title of web view controller's navigation item [[webviewcontroller navigationitem] settitle:[entry title]]; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming [[channel items] count]; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nslog(@"table cell processing"); cell *cell = [tableview dequeuereusablecellwithidentifier:@"cell"]; if (cell == nil) { cell = [[cell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"]; } rssitem *item = [[channel items] objectatindex:[indexpath row]]; [[cell titlelabel] settext:[item title]]; //middle label (actionable) [[cell authorlabel] settext:[item author]];//left label (non-actionable) [[cell categorylabel] settext:[item category]];//right label (non-actionable) homecoming cell; }
in above snippet, xib file has been hooked cell object, has been configured in special way. have added custom fit buttons-one on top of left label (title) , other on top of right label(category) create them separably user interactable within of whole cell itself. buttons have been set custom type not obscure corner labels underneath. have created 2 action methods supposed passed messages cell object button objects (on top of corner labels). these 2 methods not part of command flow during runtime.when tap on corners of cell (on these 2 buttons), entire cell gets selected , "-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath" message passed instead. doing wrong code? kindly assist.. have wasted lot of time on simple task.. none of 2 nslog loggings- "author tapped" , "category tapped" show in console.. pls help.
objective-c cocoa-touch uitableview
No comments:
Post a Comment