显示一个tableView弹出窗口(覆盖整个屏幕)

时间:2016-08-06 16:55:51

标签: ios uitableview swift2

我想要实现的目标就在this库中,但唯一的问题是,如果我要显示的数据量很大,这个库就不好了

我现在拥有的:

enter image description here

如你所见,它是一个ViewController,它包含行并显示为弹出窗口而不覆盖整个屏幕

但是当行的数据很长时,我无法扩展行的高度,这就是我的数据被截断的原因 说我的第一行标签文字是: apple ,在我的第二行标签文字中是:香蕉是一种可食用的水果,植物学上是一种浆果,产自通过Musa属的几种大型草本开花植物。在这种情况下,第二行将截断文本(这就是我的问题)

如何获得此多线(展开行高)?我必须自己创建一些东西,或者我们已经有了这个库吗?或者我有其他选择请告诉我

这就是我想要的样子:

enter image description here

1 个答案:

答案 0 :(得分:0)

我的一个上一个。项目我已经实现了你需要它的方式。我们可以像上面那样实现任何库,而不是使用任何库。

步骤1:根据需要使用xib制作视图控制器。喜欢这个

http://output.jsbin.com/cudimos

第2步:在自定义提醒中创建我们需要的自定义单元格。在那里创建一个标签,确保          为该标签选择零的行数,并给出顶部,底部,左侧和右侧约束。

步骤3:现在在视图控制器中写下代码。

    //MARK: Variable declaration 

     let suggestionsView = SuggestionsVC(nibName: "SuggestionsVC", bundle: nil)

     var blurEffectView : UIVisualEffectView?


    //MARK: Show custom view & remove custom view

     @IBAction func showAlert(sender: AnyObject)
     {
        showSuggestionView()
     }

     func showSuggestionView()
     {

        let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Dark)
        blurEffectView = UIVisualEffectView(effect: blurEffect)
        blurEffectView!.userInteractionEnabled = true
        blurEffectView!.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.removeSuggestionsView)))

        if !UIAccessibilityIsReduceTransparencyEnabled()
        {
            self.view.backgroundColor = UIColor.clearColor()

            blurEffectView!.frame = self.view.bounds


           self.view.addSubview(blurEffectView!)
        }
        else
        {
            self.view.backgroundColor = UIColor.blackColor()
        }

        suggestionsView.view.frame = CGRectMake(30,0, self.view.frame.size.width - 30, 260
        )

        suggestionsView.view.center = CGPointMake((self.view.bounds.width)/2,(self.view.bounds.height)/2)
        suggestionsView.cancelButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)
        suggestionsView.confirmButton.addTarget(self, action: #selector(self.removeSuggestionsView), forControlEvents: UIControlEvents.TouchUpInside)


        suggestionsView.listTableView.registerNib(UINib(nibName: "SampleTableViewCell", bundle: nil), forCellReuseIdentifier: "SampleTableViewCell")

        suggestionsView.listTableView.estimatedRowHeight = 44.0

        suggestionsView.listTableView.rowHeight = UITableViewAutomaticDimension

        self.view.addSubview(suggestionsView.view)

        suggestionsView.listTableView.dataSource = self


     }

     func removeSuggestionsView()
     {
        suggestionsView.view.removeFromSuperview()
        blurEffectView!.removeFromSuperview()
        self.view.backgroundColor = UIColor.lightGrayColor()
     }

     //MARK: TableView DataSource

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return 5
    }

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

        let cell: SampleTableViewCell = (tableView.dequeueReusableCellWithIdentifier("SampleTableViewCell") as? SampleTableViewCell)!

        if indexPath.row % 2 == 0
        {
             cell.sampleText.text = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa."
        }
        else
        {
             cell.sampleText.text = "Lorem ipsum "
        }
        return cell
    }

此外,您可以自定义blurEffect和动画以显示上述视图。我希望这能帮到您。它看起来像这样。

enter image description here