键盘出现时偏移UITableView内容时出错

时间:2016-01-29 12:44:20

标签: ios swift uitableview uiscrollview

此问题已在此处提出

  

Offset UITableView Content When Keyboard Appears

在目标C中。我试图在Swift中实现接受的答案但是徒劳无功。

我有一个TableView,当键盘出现时我想要偏移表视图,我已按如下方式编写代码 -

viewWillAppear()

self.automaticallyAdjustsScrollViewInsets = false
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)

然后 -

func keyboardWillShow(notification: NSNotification)
    {
        let contentInsets:UIEdgeInsets!
         let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue()
         if UIInterfaceOrientationIsPortrait(UIApplication.sharedApplication().statusBarOrientation)
         {
            contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize!.height), 0.0)
          }
        else
         {
            contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize!.width), 0.0)
          }
        self.TableVieww.contentInset = contentInsets;
        self.TableVieww.scrollIndicatorInsets = contentInsets;



        TableVieww.scrollToRowAtIndexPath(self.editingIndexPath, atScrollPosition: UITableViewScrollPosition.Top, animated: true)

    }

但是我收到错误 - 类型'SearchVC'的值没有属性'editingIndexPath'

0 个答案:

没有答案