我一直在关注XLpagerTabStrip cocoapods扩展,在我的视图控制器顶部设置一个标签栏(https://github.com/xmartlabs/XLPagerTabStrip).我正在实现ButtonBarPagerTabStripViewController并完全按照步骤,但UIScrollView不显示子视图控制器.
我认为这是因为在示例中,子视图控制器是以编程方式而不是在故事板中设置的,而我的当前设置在故事板中,因此没有显示任何内容,但我无法看到连接子视图通过故事板查看ButtonBarController的控制器.
有没有办法使用故事板显示子视图控制器,还是必须以编程方式完成?
GitHub页面表示要实现以下功能(但是如果您的子视图控制器是通过故事板设置的,那么这似乎不起作用):
override public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
{
return [MyChildViewController(), MySecondChildViewController()]
}
Run Code Online (Sandbox Code Playgroud) func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "ExerciseMenuCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ExerciseOptionTableViewCell
let currentWorkout = workouts[indexPath.row]
cell.nameLabel!.text = currentWorkout.name
cell.photoImageView.image = currentWorkout.filename
cell.startWorkout.tag = indexPath.row
cell.startWorkout.addTarget(self, action:Selector("workoutAction:"), forControlEvents: .TouchUpInside)
cell.infoWorkout.tag = indexPath.row
cell.infoWorkout.addTarget(self, action:Selector("infoAction:"), forControlEvents: .TouchUpInside)
return cell
}
Run Code Online (Sandbox Code Playgroud)
startWorkout和infoWorkout都会导致应用程序崩溃,并显示错误消息"无法识别的选择器已发送到实例".
按钮操作中的代码示例.我试图返回按钮的indexPath,然后我可以采取行动.
@IBAction func workoutAction(sender: AnyObject) {
let buttonTag = sender.tag
print(buttonTag)
}
Run Code Online (Sandbox Code Playgroud)
确切的错误信息:
016-06-17 18:34:30.722练习[4711:245683] - [Exercises.ExerciseMenu beginWorkout:]:无法识别的选择器发送到实例0x7fb47874a4b0 2016-06-17 18:34:30.727练习[4711:245683]***因未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [Exercises.ExerciseMenu beginWorkout:]:无法识别的选择器发送到实例0x7fb47874a4b0'
我正在尝试从我的视图控制器设置子视图弹出窗口并使用视觉格式约束来定位项目.我希望子视图看起来像这样,tableView的高度为150 pts,imageView的高度为100 pts,titleLabel的高度为50 pts,位于imageView的左下角:
为了尝试实现这一点,我使用了以下代码:
override func didMoveToSuperview() {
super.didMoveToSuperview()
// Add views
addSubview(titleLabel)
addSubview(tableView)
addSubview(imageView)
// Setup constraints
heightAnchor.constraint(equalToConstant: 250).isActive = true
var constraints = [NSLayoutConstraint]()
let views: [String: UIView] = ["imageView": imageView, "titleLabel": titleLabel, "tableView": tableView]
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[tableView(150)]|", options: [], metrics: nil, views: views)
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|[titleLabel][tableView]|", options: [], metrics: nil, views: views)
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|[titleLabel(20)]|", options: [], metrics: nil, views: views)
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|[imageView(100)][tableView]|", options: [], metrics: nil, views: views)
constraints += …Run Code Online (Sandbox Code Playgroud)