Created
September 7, 2014 14:02
-
-
Save mchirico/5810f53df77fddec68cd to your computer and use it in GitHub Desktop.
Working with UIViewController, UITableViewDataSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// MainViewController.swift | |
// AddEvents | |
// | |
// Created by Michael Chirico on 9/6/14. | |
// Copyright (c) 2014 Michael Chirico. All rights reserved. | |
// | |
import UIKit | |
import CoreData | |
class MainViewController: UIViewController, UITableViewDataSource { | |
@IBOutlet weak var tableViewCell0: UITableView! | |
@IBOutlet weak var tableViewCell1: UITableView! | |
var data = ["one","two","three","four"] | |
var dataII = ["a","b","c","d","e","f"] | |
var count=0 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
} | |
override func viewDidAppear(animated: Bool) { | |
tableViewCell0.reloadData() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func numberOfSectionsInTableView(tableView: UITableView!) -> Int { | |
// #warning Potentially incomplete method implementation. | |
// Return the number of sections. | |
return 1 | |
} | |
func tableView(tableView: UITableView, | |
cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |
//let cell = UITableViewCell(style: UITableViewCellStyle.Value2, reuseIdentifier: nil) | |
var ReuseID : String? | |
if tableView == tableViewCell0 { | |
ReuseID="Cell0" | |
} | |
if tableView == tableViewCell1 { | |
ReuseID="Cell1" | |
} | |
//let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: ReuseID) | |
let cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: nil) | |
if tableView == tableViewCell0 { | |
if (cell.detailTextLabel != nil) { | |
cell.detailTextLabel!.text = "DETAIL" | |
cell.textLabel!.text = data[indexPath.item] | |
} | |
} | |
if tableView == tableViewCell1 { | |
if (cell.detailTextLabel != nil) { | |
cell.detailTextLabel!.text = "Two" | |
cell.textLabel!.text = dataII[indexPath.item] | |
} | |
} | |
return cell | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
println("tableView \(tableView)") | |
if tableView == tableViewCell0 { | |
return data.count | |
} | |
if tableView == tableViewCell1 { | |
return dataII.count | |
} | |
return 3 | |
} | |
/* | |
func sectionIndexTitlesForTableView(tableView: UITableView!) { | |
} | |
*/ | |
/* | |
// MARK: - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { | |
// Get the new view controller using segue.destinationViewController. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Xcode beta7 is forcing this type of style