IOS: table view with main title, subtitle, image type UITableView
Last Update:2015-10-28
Source: Internet
Author: User
<span id="Label3"></p><p><p>Make an address book, including name, phone, avatar, and set the table view type to Uitableviewcellstylesubtitle</p></p><p><p>:</p></p><p><p></p></p><p><p>Create a Contact's class, initialize the data</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Implementing the display of tabular content in a view controller</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre> 1 #import "ViewController.h" 2 #import "Contact.h" 3 #define NUM 4 5 @interface Viewcontroller () <uitableviewdatas Ource,uitableviewdelegate> 6 @property (weak, nonatomic) iboutlet uitableview *tableview; 7 @property (strong,nonatomic) Nsmutablearray *contacts; Number of contact groups 8 @end 9 @implementation ViewController11-(void) viewDidLoad13 {+ [super viewdidload];15//initialization 16 For (int i=0; i<num; i++) + {*contact = [[contact alloc]initwithcontactname:[nsstring stringwi thformat:@ "name%d", i] andtelphonenumber:[nsstring stringwithformat:@ "tel:1876645%04d", arc4random_uniform (NUM)]; [self.contacts addobject:contact];20}21 22//set Data source and proxy Self.tableView.dataSource = self;24 Self.tableView.delegate = self;25}26 #pragma mark-tableview data source method 28//number of lines per section-(nsinteger) tableView: (uita Bleview *) tableView numberofrowsinsection: (nsinteger) section30 {return self.contacts.count;32}33//set contents of each cell 34- (uitableViewcell *) tableView: (uitableview *) tableView cellforrowatindexpath: (nsindexpath *) indexPath35 {36//1. According to reuseidentifier, first go to the object pool to find the reusable cell object, the nsstring *reuseidentifier = @ "contactcell"; UITableViewCell *cell = [self.tableview dequeuereusablecellwithidentifier:reuseidentifier];39//2. If you do not find it, create a Cell object for yourself. if (cell = = Nil) 41 {uitableviewcell = [[] Alloc]initwithstyle:uitableviewcellstylesubtitle reuseidentifier:reuseidentifier];43 }44 45//3. Setting the contents of a Cell object 46 47//set Image [cell.imageview Setimage:[uiimage imagenamed:[nsstring string withformat:@ "%d.png", arc4random_uniform (9)]]];49//set main title, cell.textLabel.text = [self.contacts[indexpath.row] con Tactname];51//set subtitle Cell.detailTextLabel.text = [self.contacts[indexpath.row] telphonenumner];53 54 55 Set Font Color Cell.textLabel.textColor = [uicolor orangecolor];57 cell.detailTextLabel.textColor = [uicolor Bluec olor];58 return cell;60}61#pragma mark-tableview Agent method 63//set line high-(cgfloat) tableView: (uitableview *) tableView heightforrowatindexpath: ( Nsindexpath *) indexPath65 {70;67}68 69//lazy load (override get method)-(nsmutablearray*) contacts71 {if (!_contacts) _contacts = [nsmutablearray arraywithcapacity:num];75}76 return _contacts;77}78 @end</pre><p><p> IOS: table view with main title, subtitle, image type UITableView </p> </p></span>