目前的VC模式高于其他VC - 两者都可触摸

时间:2017-07-04 17:26:21

标签: ios swift modalviewcontroller

我想在另一个VC上面显示一个VC,但希望它们都是可点击和负责的。

我有一个文本字段,用于打印每个@ -sign后面的字符串。

当写一个@时,我有一个VC,在第一个VC上方弹出一个小的tableview,后面应该代表名字中包含打印出的字符串的用户。

我需要第一个vc仍然负责,因为目前我无法点击第一个VC上的按钮和文本字段,当第二个VC弹出时,即使我可以看到所有内容(将背景设置为清除)。 / p>

        if commentTextField.text!.contains("@"){
        print("changed textField")
        let vc = self.storyboard?.instantiateViewController(withIdentifier: "suggestedUsersViewController") as  UIViewController!
        vc?.modalPresentationStyle = .overCurrentContext
        vc?.view.backgroundColor = .clear


        present(vc!, animated: true, completion: nil)

    }

我如何得到@ - sign

背后的帖子
        let caption = commentTextField.text


    let words = caption?.components(separatedBy: CharacterSet.whitespacesAndNewlines)
    for var word in words! {
            if word.hasPrefix("@") {
                word = word.trimmingCharacters(in: CharacterSet.punctuationCharacters)

                print("wort ist", word)
            }
    }

目前它只是弹出第一个vc然后它不再可点击而且我无法更改文本字段

图片 The first VC (where you write the comment and link users

The TableView which pops up when a @ is written in the commentTextField

1 个答案:

答案 0 :(得分:1)

present函数将使第二个视图控制器覆盖整个页面,您将无法再从屏幕访问顶部视图控制器下方的视图控制器。

要实现目标,您需要在视图上放置UITableView,然后继续显示或隐藏视图。如果你真的想要另一个视图控制器,你可以创建一个包含视图并嵌入到另一个view controller的segue,就像这样

enter image description here

相关问题