Preparation 1. Select the Project to Support arc 2. Drag a uitableview using IB and connect the delegated code to display simple text and images with uitableview
# Import <uikit/uikit. h> @ interface viewcontroller: uiviewcontroller @ property (strong, nonatomic) iboutlet uitableview * mtableview; @ property (strong, nonatomic) nsarray * List; // store list data @ end
# Import "viewcontroller. H "@ interface viewcontroller () @ end @ implementation viewcontroller @ synthesize mtableview, list;-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib. nsarray * array = [[nsarray alloc] initwithobjects: @ "No.1", @ "No. 2", @ "No. 3", @ "No. 4", @ "No. 5 ", @ "No. 6", nil]; List = array;}-(void) viewdidunload {[Super viewdidunload]; // rele ASE any retained subviews of the main view.}-(bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation {return (interfaceorientation! = Uiinterfaceorientationportraitupsidedown);} // number of rows of data in the data source delegate // tableview-(nsinteger) tableview :( uitableview *) tableview numberofrowsinsection :( nsinteger) Section {return [list count];} // content of each row of data-(uitableviewcell *) tableview :( uitableview *) tableview cellforrowatindexpath :( nsindexpath *) indexpath {static nsstring * tableviewidentifier = @ "tableviewidentifier "; uitableviewcell * cell = [tableview identifier: tableviewidentifier]; If (cell = nil) {Cell = [[uitableviewcell alloc] initwithstyle: uitableviewcellstyledefault reuseidentifier: tableviewidentifier];} nsuinteger ROW = [indexpath row]; cell. textlabel. TEXT = [list objectatindex: Row]; // Add image uiimage * image = [uiimage imagenamed: @ "1.png"]; [cell. imageview setimage: Image]; return cell;} @ end
If you have any errors, questions, or unreasonable information, please advise. Thank you.