objective c - iOS Swift - Custom UITableViewCell -
i sure question has been asked , answered in objective c. using swift , wondering how customize uitableviewcell properly. followed tutorial here http://www.appcoda.com/customize-table-view-cells-for-uitableview/ stuck @ initializing , using custom class , xib file created. yes, noob. here have standard cell without customization:
override func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell! { allow cell: uitableviewcell = uitableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: "mycell") cell.text = postmgr.posts[indexpath.section].title cell.detailtextlabel.text = postmgr.posts[indexpath.section].description homecoming cell }
if can translate obj c in tutorial swift great. here is:
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"simpletablecell"; simpletablecell *cell = (simpletablecell *)[tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { nsarray *nib = [[nsbundle mainbundle] loadnibnamed:@"simpletablecell" owner:self options:nil]; cell = [nib objectatindex:0]; } cell.namelabel.text = [tabledata objectatindex:indexpath.row]; cell.thumbnailimageview.image = [uiimage imagenamed:[thumbnails objectatindex:indexpath.row]]; cell.preptimelabel.text = [preptime objectatindex:indexpath.row]; homecoming cell;
}
not sure if that's how works ios7/8. if has improve , easier way of customizing cell, allow me know in swift language.
i appreciate help already. beginner, please bear me :)
km
i ported tutorial sample app swift
. i'am still using same customtableviewcell written in objective-c (used bridging header avail class). cellforrowindexpath
looks
func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell! { var cell:simpletablecell! = tableview.dequeuereusablecellwithidentifier(simpletableidentifier) as? simpletablecell if (cell == nil) { allow nib:array = nsbundle.mainbundle().loadnibnamed("simpletablecell", owner: self, options: nil) cell = nib[0] as? simpletablecell } cell.namelabel.text = tabledata[indexpath.row] cell.thumbnailimageview.image = uiimage(named:thumbnails[indexpath.row]) cell.preptimelabel.text = preptime[indexpath.row]; homecoming cell; }
find finish source code here: tableviewapp-swift
ios objective-c xcode uitableview swift
No comments:
Post a Comment