【问题标题】:How to remove the uiview I created from navigationController when I move forward or back to next page?当我前进或后退到下一页时,如何删除我从 navigationController 创建的 uiview?
【发布时间】:2016-01-06 08:31:09
【问题描述】:

我以编程方式创建了一个视图并将其作为子视图添加到 navigationController。我现在面临的问题是当我前进到下一页或上一页时视图没有被删除。可以做些什么来删除视图或仅将视图包含在导航控制器的特定视图控制器中?

  self.footerView = UIView(frame: CGRectMake(0, UIScreen.mainScreen().bounds.height - 40, tableView.frame.size.width, 40))
        self.footerView.tag == 1
        footerView.backgroundColor = themeColor
        let totalLabel = UILabel(frame: CGRectMake(16, 8, footerView.frame.width/2, 30))
        totalLabel.text = "Rs. 200"
        totalLabel.textColor = UIColor.whiteColor()
        let button = UIButton(type:UIButtonType.Custom)

        button.frame =  CGRectMake(footerView.frame.width/2 - 16, 8, footerView.frame.width/2, 30)
        button.layer.masksToBounds = true
        button.setTitle("Save and Continue", forState: .Normal)
        button.setTitleColor(UIColor.whiteColor(), forState: .Normal)
        button.addTarget(self, action: "saveButonPressed:", forControlEvents: .TouchUpInside)
        button.layer.borderColor = UIColor.whiteColor().CGColor
        button.layer.borderWidth = 2
        button.layer.cornerRadius = 8
        footerView.addSubview(totalLabel)
        footerView.addSubview(button)
        self.navigationController?.view.addSubview(footerView)

【问题讨论】:

  • 可以粘贴视图创建和添加的代码,文件名吗?
  • 'self.footerView = UIView(frame: CGRectMake(0, UIScreen.mainScreen().bounds.height - 40, tableView.frame.size.width, 40)) self.footerView.tag = = 1 let button = UIButton(type:UIButtonType.Custom) button.frame = CGRectMake(footerView.frame.width/2 - 16, 8, footerView.frame.width/2, 30) button.layer.masksToBounds = true 按钮。 setTitle("保存并继续", forState: .Normal) button.setTitleColor(UIColor.whiteColor(), forState: .Normal) footerView.addSubview(button) self.navigationController?.view.addSubview(footerView)'
  • 编辑您的问题并粘贴代码,使其可读。谢谢
  • 您在哪里添加了此代码?请添加文件名
  • 添加视图控制器类的完整代码

标签: swift uiview uinavigationcontroller uinavigationitem


【解决方案1】:

在 ViewController 中创建相同的视图。

let customView = //your view creation code.
self.view.addSubview(customView);
//this will add view to your viewcontroller's view, not in navigationContoller.

你可以删除视图,

customView.removeFromSuperview()

【讨论】:

  • 我在 navigationcontroller 中添加视图,我使用的视图控制器是 UITableviewcontroller
猜你喜欢
  • 2018-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-31
  • 1970-01-01
  • 2013-03-15
  • 1970-01-01
相关资源
最近更新 更多