Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // PridatViewController.swift
- // zoznam knih
- //
- // Created by Patrik on 24.4.2015.
- // Copyright (c) 2015 Patrik Belis. All rights reserved.
- //
- import UIKit
- import CoreData
- public class PridatViewController: UITableViewController,UITableViewDataSource, UITableViewDelegate {
- override public func viewDidLoad() {
- super.viewDidLoad()
- self.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: Selector("saveTapped")), animated: true)
- }
- public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 5
- }
- public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
- 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)
- 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")
- }
- func saveTapped(){
- if (cell!.textField.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 = cell!.textField.text
- pridat.autor = cell!.textField.text
- pridat.rok = cell!.textField.text
- pridat.vydavatelstvo = cell!.textField.text
- pridat.strany = cell!.textField.text
- obsah.save(nil)
- }
- return cell!
- }
- public override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement