You need to use the UiTableViewController Class It Better. If you need to use UiView Controller Then:
import UIKit
import QuartzCore
class OthersViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate {
let arrData = ["Row 1","Row 2","Row 3","Row 4","Row 5"];
let dict = NSMutableDictionary()
let arrImage = ["image 1","image 2","image 3","image 4","image 5","image 6"];
let kLCellIdentifier = "CellIdentifier"
var tblVc = UITableView();
override func viewDidLoad() {
dict.setObject(arrData, forKey: "dsd")
super.viewDidLoad()
self.title = "Others"
self.view.backgroundColor = UIColor.clearColor()
tblVc.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)
tblVc.delegate = self;
tblVc.dataSource = self;
tblVc.tableFooterView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 0))
tblVc.backgroundColor = UIColor.clearColor();
tblVc.separatorColor = UIColor.redColor();
self.view.addSubview(tblVc);
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
return arrData.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{
var cell = tableView.dequeueReusableCellWithIdentifier(kLCellIdentifier) as UITableViewCell!
if !cell {
cell = UITableViewCell(style:.Default, reuseIdentifier: kLCellIdentifier)
}
cell.backgroundColor = UIColor.clearColor()
cell.textLabel.text = arrData[indexPath.row]
cell.image = UIImage(named: "\(arrImage[indexPath.row])");
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyle.None;
return cell;
}
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat
{
return 60;
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
switch (indexPath.row) {
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
case 5:
break;
default:
break;
}
}
user1671097
source
share