Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import CoreData
- public class PridatViewController: UITableViewController,UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
- var activeTextField: UITextField!
- override public func viewDidLoad() {
- super.viewDidLoad()
- }
- public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 5
- }
- public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- var cell = tableView.dequeueReusableCellWithIdentifier("Cell" , forIndexPath : indexPath) as? TableViewCell
- if cell == nil
- {
- cell = TableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
- }
- if (indexPath.row == 0) {
- cell!.configure("Názov knihy")
- }
- if (indexPath.row == 1) {
- cell!.configure("Meno autora")
- }
- if (indexPath.row == 2) {
- cell!.configure("Rok vydania")
- }
- if (indexPath.row == 3) {
- cell!.configure("Vydavateľstvo")
- }
- if (indexPath.row == 4) {
- cell!.configure("Počet strán knihy")
- }
- return cell!
- }
- public func textFieldDidBeginEditing(textField: UITextField) {
- activeTextField = textField
- }
- public func textFieldDidEndEditing(textField: UITextField) {
- let textFieldPosition = textField.convertPoint(CGPointZero, toView: self.tableView)
- if self.tableView.indexPathForRowAtPoint(textFieldPosition) == nil {
- return
- }
- let indexPath = self.tableView.indexPathForRowAtPoint(textFieldPosition)!
- var cell = self.tableView.cellForRowAtIndexPath(indexPath) as! TableViewCell
- }
- @IBAction public func saveTapped(){
- if activeTextField.text.isEmpty {
- let alert = UIAlertView()
- alert.title = "Nevyplnené údaje"
- alert.message = "Musíš vyplniť všetky údaje o knihe."
- alert.addButtonWithTitle("Ok")
- alert.show()
- }
- let appDel: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
- let obsah: NSManagedObjectContext = appDel.managedObjectContext!
- let entity = NSEntityDescription.entityForName("List", inManagedObjectContext: obsah)
- var pridat = Model(entity: entity! , insertIntoManagedObjectContext: obsah)
- pridat.kniha = activeTextField.text
- pridat.autor = activeTextField.text
- pridat.rok = activeTextField.text
- pridat.vydavatelstvo = activeTextField.text
- pridat.strany = activeTextField.text
- obsah.save(nil)
- }
- public override func didReceiveMemoryWarning() {
- didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement