【发布时间】:2014-10-14 15:59:00
【问题描述】:
我在 Stackoverflow 上阅读了一个关于使视图控制器透明的问题,以便在显示时仍然可以看到父视图控制器。我能够这样做:
但是现在当我单击添加主题时,表格视图不会像这样将主题添加到我的表格视图中(这是点击“+”按钮时出现在上述视图后面的视图):
但是如果我退出主菜单并返回到表格视图,它会像这样显示列表(这是我点击“添加主题”时想要的)。
我认为这是因为 tableView.reloadData() 在我的 ViewWillAppear 函数中。
考虑到这一点,我将tableViewClass.tableView.reloadData 添加到“添加主题”按钮操作中,以便在按下按钮后立即重新加载数据,但是我得到fatal error: found nil while unwrapping optional value 并突出显示tableViewClass.tableView.reloadData
我知道一旦出现新的主题视图控制器以便在后面显示它,父视图控制器(一个带有表格视图的控制器)不会被杀死。这就是为什么从未调用“ViewWillAppear”的原因。
我仍然有点困惑为什么它会崩溃……这是我的按钮代码:
@IBAction func btnAddTask_Click(sender: UIButton){
subMngr.addSubjectMonA(txtSubject.text, time1: txtTime.text, time2: txtTime2.text, col: monAview.ColorValue)
self.view.endEditing(true)
var appDel: AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
var context: NSManagedObjectContext = appDel.managedObjectContext!
var newCell = NSEntityDescription.insertNewObjectForEntityForName("SubjectsEntity", inManagedObjectContext: context) as NSManagedObject
newCell.setValue(txtTime.text, forKey: "starttime")
newCell.setValue(txtSubject.text , forKey: "title")
newCell.setValue(txtTime2.text , forKey: "endtime")
newCell.setValue(monAview.ColorValue, forKey: "color")
context.save(nil)
txtSubject.text = ""
txtTime.text = ""
txtTime2.text = ""
MondayAClass.TableView.reloadData() // ERROR HERE
dismissViewControllerAnimated(true, completion: nil)
}
任何帮助将不胜感激,谢谢:)
编辑
这是我展示视图控制器并使其透明的代码:
@IBAction func addInfo(sender: AnyObject) {
let story: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let monAadd = story.instantiateViewControllerWithIdentifier("MondayAadd") as MondayAadd
monAadd.view.backgroundColor = UIColor.clearColor()
monAadd.modalPresentationStyle = UIModalPresentationStyle.Custom // If this line is taken out everything works fine
self.presentViewController(monAadd, animated: true, completion: nil)
}
【问题讨论】:
-
什么是
MondayAClass,为什么它有一个名为TableView的属性?为什么不在UITableViewController实例上使用tableView属性?
标签: ios uitableview swift ios8 xcode6