ios - Custom UITableViewCell Class Issue -
i've read quite few tutorials online how create custom cell subclass, i'm still little confused. when try follow instructions found in question, end errors tableview not valid property object of viewcontroller.
i've created new subclass of uitableviewcell
, called custombookclass
. i've hooked properties custombookclass.h
file.
#import <uikit/uikit.h> @interface custombookcell : uitableviewcell @property (weak, nonatomic) iboutlet uiimageview *bookimage; @property (weak, nonatomic) iboutlet uilabel *booktitle; @property (weak, nonatomic) iboutlet uilabel *dateadded; @end
i go viewcontroller.m
file edit viewdidload
method.
- (void)viewdidload { [super viewdidload]; [self.tableview.delegate = self]; [self.tableview.datasource=self]; [self.tableview registerclass:[custombookcell class]forcellreuseidentifier:@"custom cell"]; }
i error on tableview, saying property doesn't exist, though in viewcontroller.h
file, i'm including table view.
#import <uikit/uikit.h> @interface viewcontroller : uiviewcontroller <uitableviewdelegate, uitableviewdatasource> @end
i'm sure i'm missing obvious here, first time trying this. can me out? thanks!
uiviewcontroller
not have property. if assign delegate , datasource protocols it. there couple of things can however.
- link table view
viewcontroller
yourself. means, create property/outlet calledtableview
. - inherit
uitableviewcontroller
instead ofuiviewcontroller
.
both should work.
edit: oh , lines:
[self.tableview.delegate = self]; [self.tableview.datasource=self];
don't make sense. should either:
self.tableview.delegate = self;
,self.tableview.datasource = self;
- or
[self.tableview setdelegate:self];
,[self.tableview setdatasource:self]
with 1 being preferred. (edit: option #2 incorrect code, bad.)
Comments
Post a Comment