Skip to content

Instantly share code, notes, and snippets.

@yakout
Created August 1, 2016 19:36
Show Gist options
  • Save yakout/a8aa7fab0cc84c6dcef2fb45e1510cd3 to your computer and use it in GitHub Desktop.
Save yakout/a8aa7fab0cc84c6dcef2fb45e1510cd3 to your computer and use it in GitHub Desktop.
//
// friendsViewController.swift
// calculator
//
// Created by Ahmed Yakout on 7/31/16.
// Copyright © 2016 iYakout. All rights reserved.
//
import UIKit
class friendsViewController: UIViewController, UITableViewDataSource {
override func viewDidLoad() {
print("friendsViewController did load")
let user1 = User("ahmed")
let user2 = User("Ali")
let user3 = User("hamada")
let user4 = User("joe")
let user5 = User("hoba")
friends.append(user1)
friends.append(user2)
friends.append(user3)
friends.append(user4)
friends.append(user5)
tableView.dataSource = self
// tableView.delegate = self
}
@IBOutlet weak var tableView: UITableView!
var friends = [User]()
// confirming to UITableViewDataSource protocol
// MARK: UITextFieldDelegate Methods
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("# of rows returned")
return friends.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print(friends.count)
//let friendCell = UITableViewCell()
let friendCell = tableView.dequeueReusableCellWithIdentifier("friendCell", forIndexPath: indexPath)
friendCell.textLabel?.text = friends[indexPath.row].email
return friendCell
}
// // MARK: UITableViewDelegate Methods
// func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
// tableView.deselectRowAtIndexPath(indexPath, animated: true)
//
// let row = indexPath.row
// print(friends[row])
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment