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.

  1. link table view viewcontroller yourself. means, create property/outlet called tableview.
  2. inherit uitableviewcontroller instead of uiviewcontroller.

both should work.

edit: oh , lines:

[self.tableview.delegate = self]; [self.tableview.datasource=self]; 

don't make sense. should either:

  1. self.tableview.delegate = self; , self.tableview.datasource = self;
  2. or [self.tableview setdelegate:self]; , [self.tableview setdatasource:self]

with 1 being preferred. (edit: option #2 incorrect code, bad.)


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -