iphone - how to create custom tableViewCell from xib -
i want create custom tableviewcell on want have uitextfield editing possibility. created new class xib. add tableviewcell element. drag on uitextfield. added outlets in class , connect them together. in tableview method cellforrowatindexpath create custom cells, not custom cells - usual cells. how can fix problem, , why is? thanx!
//editcell. h
#import <uikit/uikit.h> @interface editcell : uitableviewcell { iboutlet uitextfield *editrow; } @property (nonatomic, retain) iboutlet uitextfield *editrow; @end
//editcell.m
#import "editcell.h" @implementation editcell @synthesize editrow; #pragma mark - #pragma mark view lifecycle - (void)viewdidunload { // relinquish ownership of can recreated in viewdidload or on demand. // example: self.myoutlet = nil; self.editrow = nil; } @end
//in code
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"editcell"; editcell *cell = (editcell*) [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[editcell alloc] initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellidentifier] autorelease]; } cell.editrow.text = @"some text test"; return cell; }
do not use uitableviewcell's initializer, make cell load nib:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"editcell"; editcell *cell = (editcell*) [tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"yournibnamehere" owner:self options:nil]; cell = (editcell *)[nib objectatindex:0]; } cell.editrow.text = @"some text test"; return cell; }
of course, need specify correct nib name.
Comments
Post a Comment