Skip to content

Commit

Permalink
Fix crash on iOS 8 when using text fields
Browse files Browse the repository at this point in the history
This crash was presented by Cocoa Touch:
http://stackoverflow.com/a/30719434/751268
  • Loading branch information
sberrevoets committed Nov 23, 2015
1 parent 9d03074 commit 1824503
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions Source/Text Fields/TextFieldsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import UIKit

private let kTextFieldCellIdentifier = "textFieldCell"

class TextFieldsViewController: UITableViewController {
final class TextFieldsViewController: UIViewController {

var requiredHeight: CGFloat {
return self.tableView.rowHeight * CGFloat(self.tableView.numberOfRowsInSection(0))
Expand All @@ -15,33 +15,39 @@ class TextFieldsViewController: UITableViewController {
}
}

private let tableView = UITableView(frame: .zero, style: .Plain)
private let textFields: [UITextField]

init(textFields: [UITextField]) {
self.textFields = textFields
super.init(style: .Plain)
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
self.textFields = []
super.init(nibName: nil, bundle: nil)
return nil
}

override func loadView() {
let nibName = NSStringFromClass(TextFieldCell).componentsSeparatedByString(".").last!
let cellNib = UINib(nibName: nibName, bundle: NSBundle(forClass: self.dynamicType))
self.tableView.registerNib(cellNib, forCellReuseIdentifier: kTextFieldCellIdentifier)
self.tableView.dataSource = self
self.tableView.separatorStyle = .None
self.tableView.scrollEnabled = false
}

required convenience init?(coder aDecoder: NSCoder) {
self.init(textFields: [UITextField()])
return nil
self.view = tableView
}
}

extension TextFieldsViewController/*: UITableViewDataSource */ {
extension TextFieldsViewController: UITableViewDataSource {

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.textFields.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier(kTextFieldCellIdentifier,
Expand Down

0 comments on commit 1824503

Please sign in to comment.