Basic use of Swift-uitableview (example)

Source: Internet
Author: User

Basic use of Swift-uitableview

Needless to say, just paste the code I wrote today: If the novice has what do not understand, you can send my mailbox.

//

Singleinfo.swift Personal Information

Housekeeper

//

Created by Lu Yang on 15/10/27.

Copyright? year Niven Moore. All rights reserved.

//

Import Foundation

Import UIKit

Class Singleinfo:uiviewcontroller, Uitableviewdatasource, uitableviewdelegate{

var datatable:uitableview!                                             ; Data Tables

var itemstring=[" nickname", " account"," gender", " region", " my Car")

 Current Screen Object

var screenobject=uiscreen.mainscreen(). Bounds;

Page Initialization

Override func Viewdidload() {

Super.viewdidload();

Initview();

}

/**

UI Initialization

*/

Func Initview() {

self.title= " my Profile";

SELF.VIEW.BACKGROUNDCOLOR=UICOLOR.LINGHTGREYBG();

Creattable();

}

/**

My profile table is initialized

*/

Func creattable() {

Let Datatablew:cgfloat=screenobject.width;

Let Datatableh:cgfloat=screenobject.height;

Let datatablex:cgfloat=0;

Let datatabley:cgfloat=0;

Datatable=uitableview(Frame:cgrectmake(Datatablex, Datatabley, Datatablew, Datatableh), style:UITableViewStyle.Grouped);

Datatable.delegate=self; Implementing a proxy

Datatable.datasource=self; Implementing a data source

Self.view.addSubview(dataTable);

}

1.1 Returns a group by default

Func numberofsectionsintableview(Tableview:uitableview), Int {

return 2;

}

1.2 Returns the number of rows

Func tableView(Tableview:uitableview, numberofrowsinsection section:int), Int {

If(section = = 0) {

return 1;

}else{

return 5;

}

}

1.3 return Row height

Func tableView(Tableview:uitableview, Heightforrowatindexpath indexpath:nsindexpath), cgfloat{

If(indexpath.section = = 0) {

return;

}else{

return;

}

}

1.4 Head height for each group

Func tableView(Tableview:uitableview, heightforheaderinsection section:int), cgfloat {

return ten;

}

1.5 The bottom height of each group

Func tableView(Tableview:uitableview, heightforfooterinsection section:int), cgfloat {

return 1;

}

1.6 Returning a data source

Func tableView(Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath) UITableViewCell {

Let identifier= "Identtifier";

var cell=tableview.dequeuereusablecellwithidentifier(identifier);

If(cell = = Nil) {

Cell=uitableviewcell(style:UITableViewCellStyle.Value1, Reuseidentifier:identifier);

}

If(indexpath.section = = 0) {

Cell?. Textlabel?. text= " Avatar";

}else{

Cell?. Textlabel?. Text=itemstring[Indexpath.row];

}

Cell?. Accessorytype=uitableviewcellaccessorytype.disclosureindicator;

Return cell! ;

}

1.7 Table Click event

Func tableView(Tableview:uitableview, Didselectrowatindexpath indexpath:nsindexpath) {

uncheck the style

Tableview.deselectrowatindexpath(Indexpath, animated:true);

   Get the row index of the click

If(Indexpath.row = = 0) {

Let Pushsingleinfo=singleinfo();

Pushsingleinfo.hidesbottombarwhenpushed=true; Hide Navigation bar

Self.navigationcontroller?. Pushviewcontroller(Pushsingleinfo, animated:true);

}

}

Memory Warning

Override func didreceivememorywarning() {

Super.didreceivememorywarning();

Print(" Personal Information Memory warning");

}

}

As follows:

Basic use of Swift-uitableview (example)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.