【发布时间】:2014-07-26 09:49:26
【问题描述】:
我只是将其他视图控制器的子视图添加到我当前的视图控制器(由 tableview 组成)。当用户按下行时,我添加子视图。
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
{
var vc: alertVC = alertVC()
vc.setUpData(Helper.Stored.alertViewWithPlacehlder)
self.view.addSubview(vc.view)
}
在那之后,在那个alertVC中,有IBAction。当我按下那个按钮时,我的应用程序崩溃了。我也不知道为什么。我该怎么办?调试中也没有显示任何内容。
@IBAction func cancel(sender: AnyObject)
{
NSLog("cancel");
}
编辑:下面是我在 alertVC 中的代码,哪个视图将添加到我当前的视图中。当我添加带有加载笔尖的子视图时,我收到了这个错误。我该怎么办?
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<_ttc13fastphonecard9contactvc> setValue:forUndefinedKey:]:此类与键 vwTwoBtnWithTitle 的键值编码不兼容。”
import UIKit
class alertVC: UIViewController {
var alertType: NSString = NSString()
@IBOutlet var vwTwoBtnWithTitle: UIView
override func viewDidLoad() {
super.viewDidLoad()
setUpInterface()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
class func getView() -> alertVC {
return NSBundle.mainBundle().loadNibNamed("alertVC", owner: nil, options: nil)[0] as alertVC
}
func setUpInterface()
{
self.view.backgroundColor = UIColor (white: 1, alpha: 0.5)
if(alertType == Helper.Stored.alertViewWithPlacehlder)
{
addVWTwoBtnWithTitle()
}
}
func setUpData(input : NSString)
{
alertType = input
}
func addVWTwoBtnWithTitle()
{
vwTwoBtnWithTitle.frame = CGRectMake(20, 190, 280, 160);
vwTwoBtnWithTitle.layer.borderWidth = 1
vwTwoBtnWithTitle.layer.borderColor = UIColor.blackColor().CGColor
vwTwoBtnWithTitle.layer.cornerRadius = 5
self.view.addSubview(vwTwoBtnWithTitle)
}
@IBAction func cancel(sender: AnyObject)
{
NSLog("cancel");
}
}
【问题讨论】:
-
谢谢。我已从 SWIFT 更改为 Swift
标签: ios swift tableview ibaction