2015-09-03 112 views
1

Xcode 7 beta 6后额外无零。
我单击save按钮会显示2个时间段与nil s?
我应该从哪里开始排除故障?
enter image description here点击下载按钮

2015-09-03 11:58:38.804 demoProject[27331:856955] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 1336863583_PortraitChoco_iPhone-Simple-Pad_Default 
sending profileNew object to TableViewController 
2015-09-03 11:58:46.238 demoProject[27331:856955] I'm back from other controller! 
nil 
Save btn clicked addUIViewController 
Name : Optional("txt") 
Age : Optional("22") 
Specialty : Optional("you") 
Description : Desciptionddd 
sending profileNew object to TableViewController 
2015-09-03 11:58:46.240 demoProject[27331:856955] I'm back from other controller! 
nil 

我有2个视图控制器。首先是ProfileTableViewController。其次是addUIViewController
应用流量
1.在Select场景标签加号。
2.添加名称,年龄,专长,说明。然后保存。
3.放开segue发回新的配置文件对象。
4. TableViewController更新场景记录。
现在我很困惑。我的unwind segue的实现是错误的吗?

Profile.swift

import UIKit 
class Profile { 
    var name : String; 
    var age : Int; 
    var specialty : String?; 
    var description : String?; 
    init?(name : String, age: Int, specialty : String?, description : String?){ 
     self.name = name; 
     self.age = age; 
     self.specialty = specialty; 
     self.description = description; 
     if (name.isEmpty || age < 0){ 
      return nil; 
     } 
    }; 
} 

ProfileTableViewController.swift

import UIKit 

class ProfileTableViewController: UITableViewController { 

    var profiles = [Profile](); 

    var profileNew : Profile?; 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     func loadSampleProfiles(){ 
      let profile1 = Profile(name: "Ant", age: 18, specialty: "Runner", description: "Ants are eusocial insects of the family Formicidae /fɔrˈmɪsɨdiː/ and, along with the related wasps and bees EOF"); 
      let profile2 = Profile(name: "Bee", age: 11, specialty: "Sky Diver", description: "Bees are flying insects closely related to wasps and ants, known for their role in pollination EOF"); 
      let profile3 = Profile(name: "Cat", age: 14, specialty: "Stalker", description: "The domestic cat[1][2] (Felis catus EOF"); 
      let profile4 = Profile(name: "Dog", age: 19, specialty: "Proxy", description: "In engineering a dog is a tool that prevents movement or imparts movement by offering physical obstructioEOF"); 
      let profile5 = Profile(name: "Earth", age: 20, specialty: "Supplier", description: "Earth, also called the world[n 5] (and, less frequently, Gaia[n 6] or, in Latin, Terra[26]), is the thirEOF"); 
      profiles += [profile1!, profile2!, profile3!, profile4!, profile5!]; 
     }; 
     loadSampleProfiles(); 

    } 


    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 

    // MARK: - Table view data source 

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1; 
    } 

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

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cellIdentifier = "ProfileTableViewCell"; 
     let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ProfileTableViewCell 
     let profile = profiles[indexPath.row]; 
     cell.nameLabel.text = profile.name; 
     cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator 

     return cell 
    } 

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     tableView.deselectRowAtIndexPath(indexPath, animated: true); 
     let row = indexPath.row; 
     print("Row:\(row)"); 
     print(profiles[row].name , profiles[row].age); 
     performSegueWithIdentifier("segueTest", sender: row); 
    } 

    // Mark: Actions 
    @IBAction func backFromOtherController(segue: UIStoryboardSegue) { 
     NSLog("I'm back from other controller!") 
     print(profileNew?.toString()); 

     //add the new profile 
     if(profileNew != nil){ 
      profiles += [profileNew!]; 

      //update the tableview 
      let indexPath = NSIndexPath(forRow: profiles.count, inSection: 0); 
      tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) 
      print(indexPath); 
     } 

    } 

} 

addUIController.swift

import UIKit 

class addUIViewController: UIViewController { 

    // Mark: Properties 

    @IBOutlet weak var addNameTextField: UITextField! 
    @IBOutlet weak var addAgeTextField: UITextField! 
    @IBOutlet weak var addSpecialtyTextField: UITextField! 
    @IBOutlet weak var descUIViewController: UITextView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    override func didReceiveMemoryWarning() { 
    } 

    // Mark: Actions 

    var profileNew : Profile?; 
    @IBOutlet weak var saveButton: UIButton! 

    @IBAction func saveHit(sender: AnyObject) { 
     print("Save btn clicked addUIViewController"); 
     print("Name : " + addNameTextField.text); 
     print("Age : " + addAgeTextField.text); 
     print("Specialty : " + addSpecialtyTextField.text); 
     print("Description : " + descUIViewController.text); 
     if(addNameTextField.text == nil || addAgeTextField.text == nil || addSpecialtyTextField.text == nil || descUIViewController.text == nil){ 
      self.profileNew = nil; 
      print("Got nil"); 
     } 

     let profileNew = Profile(name : addNameTextField.text!, age : Int(addAgeTextField.text!)!, specialty : addSpecialtyTextField.text!, description : descUIViewController.text!); 
     self.performSegueWithIdentifier("profileNew", sender: profileNew) 
    } 

    // MARK: - Navigation 

    // In a storyboard-based application, you will often want to do a little preparation before navigation 
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     if(segue.identifier == "profileNew"){ 
      let viewControllerReceiver = segue.destinationViewController as? ProfileTableViewController; 
      print("sending profileNew object to TableViewController"); 
      viewControllerReceiver?.profileNew = profileNew; 
     } 
    } 

} 
+0

你知道那个“'nil'”是哪里来的?如果没有,您可以添加一点额外的信息到您的“打印”调用。例如:“'print(”addNameTextField is \(addNameTextField.text)“)'”。这样你可以很容易地隔离哪个“'print”“正在打印一个零。 –

+0

@MichaelDautermann名称 - >可选( “TXT”),年龄 - >可选( “22”),专业 - >可选( “您”),说明 - > Desciptionddd。我会把我的'打印'行更多的信息。 – Sarit

回答

0

原因:Ctrl拖动save按钮Exit
解决方案:删除并通过拖放重新创建SEGUE从TitleExit