objective c - How to add UITableViewCell on UIView TableView -
i have uiview class added uitableview created uitableviewcell wants added custom cell on uitableviewcell.
- (id)initwithcoder:(nscoder *)coder{ self = [super initwithcoder:coder]; if (self) { //do somthing filtercolortableview.delegate = self; filtercolortableview.datasource = self; [self.filtercolortableview registernib:[uinib nibwithnibname:@"filtercolor" bundle:nil] forcellreuseidentifier:@"colorcell"]; colornamelist = [[colormodelclass colorlistnames]allkeys]; filtercolortableview.tablefooterview = [[uiview alloc] initwithframe:cgrectzero]; } return self; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *tableviewcellidentifier = @"colorcell"; filtercolortableviewcell *cell = [tableview dequeuereusablecellwithidentifier:tableviewcellidentifier forindexpath:indexpath]; [cell.lbl_colorname settext:@"welcome"] ; cell.lbl_colorname.textcolor = [uicolor redcolor]; [cell.colorimage setimage:[uiimage imagenamed:@"circle.png"]]; return cell; } crash report message: terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'unable dequeue cell identifier colorcell - must register nib or class identifier or connect prototype cell in storyboard' which creating cell object associated lbl_colorname , colorimage nil alway's
note: not used uiviewcontroller uiview class used in approach.
on uiview xib added uitableview , taken custom uitableviewcell in same file's owner.
first register custom cell class anytime @ or after viewdidload. having done that, the dequeue method introduced along class or nib registration dequeuereusablecellwithidentifier:forindexpath:. note new indexpath parameter.
it returns initialized cell, nil check superfluous...
filtercolortableviewcell *cell = [tableview dequeuereusablecellwithidentifier:filtertableviewcell forindexpath:indexpath]; // deleted if(cell == nil){...} 
Comments
Post a Comment