2015-06-16 38 views
-1

我在我的應用程序中使用ViewController。在ViewController中我嘗試彈出使用textfield的tableview。但有錯誤PopOver TableView,Swift IOS中的單元格出錯8

這是我的代碼彈出:

Func textFieldShouldBeginEditing(textField: UITextField) -> Bool{  

    if (textField == paymentTextField){ 
     var paymentVC = MasterPaymentTableViewController() 
     paymentVC.modalPresentationStyle = .Popover 

     paymentVC.preferredContentSize = CGSizeMake(300, 500) 

     let popOverPresentationVC = paymentVC.popoverPresentationController 

     popOverPresentationVC?.delegate = self 
     popOverPresentationVC?.permittedArrowDirections = .Down 

     popOverPresentationVC?.sourceView = textField as UIView 

     self.navigationController?.presentViewController(paymentVC, animated: true, completion: nil) 

     return false 
    } 
    } 

此錯誤的代碼:

import UIKit 
import CoreData 

class MasterPaymentTableViewController: UITableViewController { 

var myList : Array<AnyObject> = [] 
var appDel : AppDelegate! 
var context : NSManagedObjectContext! 

override func viewDidLoad() { 
    super.viewDidLoad() 


} 

override func viewDidAppear(animated: Bool) { 
    appDel = UIApplication.sharedApplication().delegate as! AppDelegate 
    context = appDel.managedObjectContext 

    let freq = NSFetchRequest(entityName: "PayMethod") 

    myList = context.executeFetchRequest(freq, error: nil)! 
    tableView.reloadData() 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

// MARK: - Table view data source 

override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 

    return 1 
} 

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 

return myList.count 
} 


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell { 

    let cellID : String = "Cell" 
    // ERROR AT HERE : unexpectedly found nil while unwrapping an Optional value 
    var cell = tableView.dequeueReusableCellWithIdentifier(cellID) as! UITableViewCell 
    // ------------- 
    if let ip = indexPath { 
    var myObject : NSManagedObject = myList[ip.row] as! NSManagedObject 

    let title = myObject.valueForKeyPath("paymentName") as! String 

    cell.textLabel!.text = title 
} 


return cell 
} 

但是,如果我打開的tableView直接不酥料餅,其工作正常

任何解? THX

+2

你真的需要投入更多細節,突出發生錯誤的地方等 – Icaro

回答

0

試試這個:

override func viewDidLoad() { 
    super.viewDidLoad() 

    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell") 
} 

,並使用dequeueReusableCellWithIdentifier:forIndexPath:方法,而不是使用dequeueReusableCellWithIdentifier:如果你期望的人來幫助你,發佈您的代碼

let cell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath:indexPath) 
+0

其作品,沒有錯誤。 thx,我只是想問,如果popover,酒吧按鈕不能顯示?只是把它展現出來? – fendy

+0

bar按鈕可以顯示在'UINavigationController'內的'NavigationBar'上 – Bannings

相關問題