I added texts into tableViewCell by using a textfield, and the order of words entered in the cell on the top of a tableView was non-alphabetical. How does it become alphabetically ordered? Is there any built-in method to do this, or do I write a method? Thank you!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var myTextField: UITextField!
var stringArray = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return stringArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = stringArray[indexPath.row]
return cell
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
return true
}
@IBAction func AddButton(sender: UIButton) {
stringArray.append(myTextField.text)
myTextField.text = nil
myTextField.resignFirstResponder()
tableView.reloadData()
}
}