Swift 5: TableView scroll to next cell - swift

Hi everyone I want some help on tableview with this tableView.isPagingEnabled = true when I call this he work but he not move to next cell with full height , how I can use it and move to next cell with full height,
this is my code :
import UIKit
private let id = "ss"
class TableView:UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: id)
tableView.isPagingEnabled = true
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 16
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: id, for: indexPath)
cell.backgroundColor = .red
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 755
}
}
I want my cell be like tiktok cell when I swipe down he move to next cell with full height ,
thank you

It really seems to me that what you want is to use a UIPageView instead of a UITableView. Below is a playground that demonstrates using UIPageView to achieve the effect I think you are describing. When the view displays, try scrolling up and down.
import UIKit
import PlaygroundSupport
func calibratedHue(hue: Int) -> Int {
guard hue >= 0 else { return 0 }
guard hue < 360 else { return 360 }
return (hue / 12) * 12
}
class ColorPageViewController : UIViewController {
var hue : Int = 0
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(
hue: CGFloat(self.hue) / 360.0,
saturation: 1.0,
brightness: 1.0,
alpha: 1.0)
}
}
class PagesOfColors : NSObject, UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController? {
var priorViewController : UIViewController? = nil
if let colorPageViewController = viewController as? ColorPageViewController {
if colorPageViewController.hue > 0 {
let newViewController = ColorPageViewController()
newViewController.hue = calibratedHue(hue: colorPageViewController.hue - 12)
priorViewController = newViewController
}
}
return priorViewController
}
func pageViewController(
_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController? {
var nextViewController : UIViewController? = nil
if let colorPageViewController = viewController as? ColorPageViewController {
if colorPageViewController.hue < 360 {
let newViewController = ColorPageViewController()
newViewController.hue = calibratedHue(hue: colorPageViewController.hue + 12)
nextViewController = newViewController
}
}
return nextViewController
}
}
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .vertical)
let pageSource = PagesOfColors()
let startingPage = ColorPageViewController()
startingPage.hue = calibratedHue(hue: 180)
pageViewController.setViewControllers([startingPage], direction: .forward, animated: false, completion: nil)
pageViewController.dataSource = pageSource
pageViewController.view.bounds = CGRect(x: 0, y: 0, width: 320, height: 480)
PlaygroundSupport.PlaygroundPage.current.liveView = pageViewController

Related

How I can pin the tableHeaderView?

Tell me, please, how I can pin the tableHeaderView on the ViewController's screen through code? I use this code, but the tableViewHeader disappears on scrolling:
import UIKit
class TestViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
lazy var tableViewTest = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
createTable()
}
private func createTable() {
self.tableViewTest = UITableView(frame: view.bounds, style: .grouped)
tableViewTest.register(TestTableViewCell.self, forCellReuseIdentifier: "Test")
self.tableViewTest.delegate = self
self.tableViewTest.dataSource = self
tableViewTest.autoresizingMask = [.flexibleWidth, .flexibleHeight]
tableViewTest.separatorInset.left = 10
tableViewTest.separatorInset.right = 10
tableViewTest.tableHeaderView = "Test Header"
view.addSubview(tableViewTest)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Test", for: indexPath) as! TestTableViewCell
cell.testLabel.text = "test label"
return cell
}
}
This is my second class:
import UIKit
class TestTableViewCell: UITableViewCell {
let testLabel = UILabel()
override func layoutSubviews() {
super.layoutSubviews()
testLabel.frame = CGRect(x: 60, y: 5, width: UIScreen.main.bounds.width - 80, height: 50)
testLabel.numberOfLines = 0
testLabel.sizeToFit()
addSubview(testLabel)
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
Try to use the implicit construct of UITableView
lazy var tableViewTest = UITableView(frame: .zero, style: .plain)
But also you need to change your table header to section header which you can define in UITableViewDelegate method
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let identifier = YourSectionHeaderView.reuseIdentifier
let headerView =
tableView.dequeueReusableHeaderFooterView(withIdentifier: identifier)
return headerView
}
By the way, I also recommend you to use constraint instead of autoresizing mask
Thank you.
This work for me:
import UIKit
class TestViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
lazy var tableViewTest = UITableView()
var segmentedControl = UISegmentedControl(items: ["Test1", "Test2", "Test3"])
override func viewDidLoad() {
super.viewDidLoad()
createTable()
configureSegmentedControl()
}
private func createTable() {
self.tableViewTest = UITableView(frame: view.bounds, style: .plain)
tableViewTest.register(TestTableViewCell.self, forCellReuseIdentifier: "Test")
self.tableViewTest.delegate = self
self.tableViewTest.dataSource = self
tableViewTest.autoresizingMask = [.flexibleWidth, .flexibleHeight]
tableViewTest.separatorInset.left = 10
tableViewTest.separatorInset.right = 10
tableViewTest.tableFooterView = UIView()
view.addSubview(tableViewTest)
}
private func configureSegmentedControl() {
segmentedControl.selectedSegmentIndex = 0
segmentedControl.frame = CGRect(x: 10, y: 150, width: UIScreen.main.bounds.width - 20.0, height: 40)
segmentedControl.layer.cornerRadius = 5.0
segmentedControl.backgroundColor = .blue
segmentedControl.selectedSegmentTintColor = .red
segmentedControl.tintColor = .white
segmentedControl.addTarget(self, action: #selector(changeSegment), for: .valueChanged)
}
#objc func changeSegment(sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
print("Test1")
case 1:
print("Test2")
default:
print("Test3")
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Test", for: indexPath) as! TestTableViewCell
cell.testLabel.text = "test label"
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return segmentedControl
}
}

Adding two UITableViews in one UIVIewController programmatically and want to change the View of Controller with UISegmentedControl

I want to change the View of my ViewController based on 2 tableVIews with segmentedControl. I have reached it with programmatic approach. I created two TableViews and One SegmentedControl. But When I change the segmentedControl it stays on the same Index but changing the View. I have to tap twice on each Segment to reach it. Why it is happening?
Here is my code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
configureFirstTableView()
}
var firstTableView = UITableView()
var secondTableView = UITableView()
func configureFirstTableView() {
firstTableView.frame = self.view.frame
firstTableView.delegate = self
firstTableView.dataSource = self
firstTableView.register(UITableViewCell.self, forCellReuseIdentifier: "FirstCell")
view.addSubview(firstTableView)
}
func configureSecondTableView() {
secondTableView.frame = self.view.frame
secondTableView.delegate = self
secondTableView.dataSource = self
secondTableView.register(UITableViewCell.self, forCellReuseIdentifier: "SecondCell")
view.addSubview(secondTableView)
}
func configureSegmentedControl() -> UISegmentedControl {
let segmentedControl = UISegmentedControl(frame: CGRect(x: 10, y: 5, width: view.frame.width - 10, height: 30))
segmentedControl.insertSegment(withTitle: "First", at: 0, animated: false)
segmentedControl.insertSegment(withTitle: "Second", at: 1, animated: false)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: #selector(changeSegmentedControlValue(_:)), for: .valueChanged)
return segmentedControl
}
#objc func changeSegmentedControlValue(_ sender: UISegmentedControl) {
switch sender.selectedSegmentIndex {
case 0:
print("1")
configureFirstTableView()
case 1:
print("2")
configureSecondTableView()
default:
break
}
}
}
extension ViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var count: Int?
if tableView == firstTableView {
count = 3
return count!
} else if tableView == secondTableView {
count = 4
return count!
}
return count!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == firstTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "FirstCell", for: indexPath)
cell.textLabel?.text = "First"
return cell
} else if tableView == secondTableView {
let cell = tableView.dequeueReusableCell(withIdentifier: "SecondCell", for: indexPath)
cell.textLabel?.text = "Second"
return cell
}
return UITableViewCell()
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = .white
v.addSubview(configureSegmentedControl())
return v
}
}

How to make web view with preview in app page?

I want show preview of web content in my app. When user click to the web view preview then it should go to the web-site.
Below my code
MainViewController.swift
import UIKit
import SDWebImage
import WebKit
class MainViewController: UIViewController, WebServiceDelegate, UITableViewDelegate, UITableViewDataSource, WKUIDelegate {
#IBOutlet weak var tableView: UITableView!
#IBOutlet weak var indicator: UIActivityIndicatorView!
var tests: [Test] = []
let defaults = UserDefaults.standard
var webService = WebService()
var webView : WKWebView!
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
override func loadView() {
let webConfig = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfig)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://www.google.com/")
let myReq = URLRequest(url: myURL!)
webView.load(myReq)
label.center = tableView.center
label.textAlignment = .center
label.text = ""
tableView.isHidden = true
indicator.isHidden = true
indicator.center = view.center
webService.delegate = self
tableView.dataSource = self
tableView.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
HHTabBarView.shared.isHidden = false
navigationController?.navigationBar.isHidden = true
Where can I use content preview?
if (defaults.object(forKey: "AccessToken") == nil) {
if let destinationView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "IntroViewController") as? IntroViewController {
if let navigator = self.navigationController {
navigator.pushViewController(destinationView, animated: false)
}
}
} else {
startLoading(withView: view, withIndicator: indicator)
webService.getTests()
I have backend parameters like
webService.getWebContents(withWebImage: "webImage", withWebTitle: "webTitle", withWebDescription: "webDescription", withWebCreater: "webCreater", withWebPubDate: "webPubdate")
}
}
I want to make a web view which is shown with preview in my
MainViewController's table views cells .
func configureCell(for cell: UITableViewCell, with item: Test) {
let testImage = cell.viewWithTag(1001) as! UIImageView
testImage.sd_setImage(with: URL(string: item.image), completed: nil)
testImage.layer.borderWidth = 0
testImage.layer.borderColor = UIColor.black.cgColor
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(Utility.scaledHeight(320))
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tests.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "projectCell", for: indexPath)
cell.selectionStyle = .none
let item = tests[indexPath.row]
configureCell(for: cell, with: item)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let destinationView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TestDetailViewController") as? TestDetailViewController {
if let navigator = self.navigationController {
navigator.pushViewController(destinationView, animated: true)
destinationView.testId = tests[indexPath.row].id
}
}
}
}
I had a navigation view on the top of the webView. Cancelled this little view. Added normal UIButton item with back arrow. navigationController?.popToRootViewController(animated:true)

iOS11 how to sync large navigation bar collapse with scroll

Using Swift 3 with Xcode 9 I'm using the large UINavigationBar view by:
if #available(iOS 11.0, *) {
navigationBar?.prefersLargeTitles = true
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: Colors.black
]
}
When I scroll a UITableView, the bar collapses too fast which creates an unwanted space:
Before:
After:
The moment I touch the UITableView the bar collapses.
The tableView has the following properties:
let rect = CGRect(
x: 0,
y: UIApplication.shared.statusBarView?.frame.height ?? 20,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height
)
let tableView = UITableView(frame: rect)
The top inset of the tableView is self.navigationController?.navigationBar.frame.height ?? 44
Also the tableView is set to:
if #available(iOS 11.0, *) {
self.contentInsetAdjustmentBehavior = .never
}
The bar is translucent and I wish to keep that. What am I missing? Help is very appreciated.
I don't know whether it will useful to you or not. But its the sample code which is working for me.
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating {
var numbers: [String] = []
let rect = CGRect(
x: 0,
y: UIApplication.shared.statusBarFrame.height ?? 20,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height
)
lazy var tableView: UITableView = {
let tV = UITableView()
tV.delegate = self
tV.dataSource = self
tV.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell")
return tV
}()
override func viewDidLoad() {
super.viewDidLoad()
numbers = generateNumbers()
self.view.backgroundColor = UIColor.white
title = "Numbers"
self.navigationController?.navigationBar.prefersLargeTitles = true
let search = UISearchController(searchResultsController: nil)
search.hidesNavigationBarDuringPresentation = false
search.searchResultsUpdater = self
search.definesPresentationContext = true
self.navigationItem.searchController = search
tableView.frame = rect
self.view.addSubview(tableView)
}
func generateNumbers() -> [String] {
var numbers = [String]()
for var i in 1..<100 {
numbers.append(String(i))
}
return numbers
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return numbers.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = self.numbers[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
func updateSearchResults(for searchController: UISearchController) {
if let text = searchController.searchBar.text, !text.isEmpty {
numbers = self.numbers.filter({ (number) -> Bool in
return number.contains(text)
})
} else {
numbers = generateNumbers()
}
self.table.reloadData()
}
}
I got it working using:
if #available(iOS 11.0, *) {
self.contentInsetAdjustmentBehavior = .always
}
And
let tableViewFrame = CGRect(
x: 0,
y: UIApplication.shared.statusBarFrame.height ?? 20,
width: UIScreen.main.bounds.width,
height: UIScreen.main.bounds.height
)
And no further TableView top insets.

Swift side bar menu complies but does not appear

I have been to following this guide [https://www.youtube.com/watch?v=qaLiZgUK2T0] for the creation of a swift sidebar menu: The code compiles, with out errors... I must be missing something simple somewhere....The menu does not appear. Please assist me with locating this issue.
The code for the menu is listed below in three files:
ViewController.swift:
import UIKit
class ViewController: UIViewController, SideBarDelegate {
var sideBar:SideBar = SideBar()
override func viewDidLoad() {
super.viewDidLoad()
sideBar = SideBar(sourceView: self.view, menuItems: ["first item","second item","third item"])
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func sideBarDidSelectButtonAtIndex(index: Int) {
}
}
SideBarTableViewController.swift:
import UIKit
protocol SideBarTableViewControllerDelegate{
func sideBarControlDidSelectRow(indexPath:NSIndexPath);
}
class SideBarTableViewController: UITableViewController {
var delegate:SideBarTableViewControllerDelegate?
var tableData:Array<String> = []
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count;
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
if cell == nil{
cell = UITableViewCell(style :UITableViewCellStyle.Default, reuseIdentifier: "Cell")
// Configure the cell...
cell!.backgroundColor = UIColor.clearColor()
cell!.textLabel.textColor = UIColor.darkTextColor()
let selectedView:UIView = UIView(frame: CGRect (x: 0, y:0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
cell!.selectedBackgroundView = selectedView
}
cell!.textLabel.text = tableData[indexPath.row]
return cell!
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
return 45.0
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
delegate?.sideBarControlDidSelectRow(indexPath)
}
}
SideBar.swift
import UIKit
#objc protocol SideBarDelegate{
func sideBarDidSelectButtonAtIndex(index:Int)
optional func sideBarWillClose()
optional func sideBarWillOpen()
}
class SideBar: NSObject, SideBarTableViewControllerDelegate {
let barWidth : CGFloat = 150;
let sideBarTableViewTopInset:CGFloat = 64.0;
let sideBarContainerView: UIView = UIView()
let sideBarTableViewController: SideBarTableViewController = SideBarTableViewController()
let orginView : UIView!
var animator: UIDynamicAnimator!
var delegate:SideBarDelegate?
var isSideBarOpen:Bool = false
override init(){
super.init()
}
init(sourceView: UIView, menuItems:Array<String>){
super.init()
orginView = sourceView
sideBarTableViewController.tableData = menuItems
animator = UIDynamicAnimator(referenceView: orginView)
let showGestureRecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
showGestureRecognizer.direction = UISwipeGestureRecognizerDirection.Right
orginView.addGestureRecognizer(showGestureRecognizer)
let hideGesturerecognizer:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "handleSwipe:")
hideGesturerecognizer.direction = UISwipeGestureRecognizerDirection.Left
orginView.addGestureRecognizer(hideGesturerecognizer)
}
func setupSideBar(){
sideBarContainerView.frame = CGRectMake(-barWidth - 1,orginView.frame.origin.y, barWidth, orginView.frame.size.height)
sideBarContainerView.backgroundColor = UIColor.clearColor()
sideBarContainerView.clipsToBounds = false
orginView.addSubview(sideBarContainerView)
let blurView:UIVisualEffectView = UIVisualEffectView(effect:
UIBlurEffect(style: UIBlurEffectStyle.Light))
blurView.frame = sideBarContainerView.bounds
sideBarContainerView.addSubview(blurView)
sideBarTableViewController.delegate = self
sideBarTableViewController.tableView.frame = sideBarContainerView.bounds
sideBarTableViewController.tableView.clipsToBounds = false
sideBarTableViewController.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
sideBarContainerView.backgroundColor = UIColor.clearColor()
sideBarTableViewController.tableView.scrollsToTop = false
sideBarTableViewController.tableView.contentInset = UIEdgeInsetsMake(sideBarTableViewTopInset, 0,0,0)
sideBarTableViewController.tableView.reloadData()
sideBarContainerView.addSubview(sideBarTableViewController.tableView)
}
func handleSwipe(recognizer:UISwipeGestureRecognizer){
if (recognizer.direction == UISwipeGestureRecognizerDirection.Left){
showSideBar(false)
delegate?.sideBarWillClose?()
}else{
showSideBar(true)
delegate?.sideBarWillClose?()
}
}
func showSideBar(shouldOpen:Bool){
animator.removeAllBehaviors()
isSideBarOpen = shouldOpen
let gravityX:CGFloat = (shouldOpen) ? 0.5 : -0.5
let magnitude:CGFloat = (shouldOpen) ? 20 : -20
let boundryX: CGFloat = (shouldOpen) ? barWidth : -barWidth - 1
let gravityBehavior:UIGravityBehavior = UIGravityBehavior(items: [sideBarContainerView])
gravityBehavior.gravityDirection = CGVectorMake(gravityX, 0)
let collisonBehavior:UICollisionBehavior = UICollisionBehavior(items: [sideBarContainerView])
collisonBehavior.addBoundaryWithIdentifier("sideBarBoundary", fromPoint: CGPointMake(boundryX, 20), toPoint: CGPointMake(boundryX, orginView.frame.size.height))
animator.addBehavior(collisonBehavior)
let pushBehavior:UIPushBehavior = UIPushBehavior(items: [sideBarContainerView], mode: UIPushBehaviorMode.Instantaneous)
animator.addBehavior(pushBehavior)
let sideBarBehavior:UIDynamicItemBehavior = UIDynamicItemBehavior(items: [sideBarContainerView])
sideBarBehavior.elasticity = 0.3
animator.addBehavior(sideBarBehavior)
}
func sideBarControlDidSelectRow(indexPath: NSIndexPath) {
delegate?.sideBarDidSelectButtonAtIndex(indexPath.row)
}
}
I went through and debugged the project file when you download the source code and all I had to do to get it to work was make a bunch of minor changes to the SideBarTableViewController.swift and everything worked for me. Here it is:
import UIKit
protocol SideBarTableViewControllerDelegate{
func sideBarControlDidSelectRow(indexPath:NSIndexPath)
}
class SideBarTableViewController: UITableViewController {
var delegate:SideBarTableViewControllerDelegate?
var tableData:Array<String> = []
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("Cell") as? UITableViewCell
if cell == nil{
cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
// Configure the cell...
cell?.backgroundColor = UIColor.clearColor()
cell?.textLabel?.textColor = UIColor.darkTextColor()
let selectedView:UIView = UIView(frame: CGRect(x: 0, y: 0, width: cell!.frame.size.width, height: cell!.frame.size.height))
selectedView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.3)
cell!.selectedBackgroundView = selectedView
}
cell?.textLabel?.text = tableData[indexPath.row]
return cell!
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 45.0
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
delegate?.sideBarControlDidSelectRow(indexPath)
}
}