2017-02-03 25 views
0

我需要滾動到bottom.When我寫滾動在viewwilAppear它不工作表的代碼表,但是當我在寫viewDidAppear相同的代碼它的工作原理,但用戶看滾動。我不希望看到的用戶,滾動如何使tableScrolling在ViewWillAppear.`滾動與迅速自動佈局cellForRowAtIndex問題

override func viewWillAppear(animated: Bool) 
{ 
    super.viewWillAppear(animated) 
    UIApplication.sharedApplication().delegate!.window!!.windowLevel = UIWindowLevelNormal 
    self.view.backgroundColor = UIColor.whiteColor() 
    viewWillAppearExecuted = true 
    executeCodeOfViewViewAppear() 
} 

func executeCodeOfViewViewAppear() { 

    if viewWillAppearExecuted { 

     viewWillAppearExecuted = false 

     if appNeedsAutoResize{ 
      self.noLongerParticipantMessageLabel.font = UIUtils.getFontForApproprieteField(.Footnote).font 
      self.typingStatusLabel.font = UIUtils.getFontForApproprieteField(.Headline).font 
     } 

     withAnimationFlag = true 

     if !self.composeBar.textView.isFirstResponder() 
     { 
      // This block will execute if compose bar is first responder 
      self.updateTableBottomCnt(value:self.composeBar.frame.size.height) 


      // Update compose bar constarint 
      if self.composeBarBottomConstraing.constant != 0 
      { 
       self.composeBarBottomConstraing.constant = 0 
      } 
     } 

     self.isOpenNextScreen = false 

     self.checkIfloginUserisActiveMember() 

     self.tabBarController?.tabBar.hidden = true 
     ChatCommonCall.sharedInstance.currentThreadIdForPush = self.threadInfo.threadId 

     // This block is used for make a responder to keyboard for send message. 
     if shouldComposeBarFirstResponder == true { 
      self.composeBar.becomeFirstResponder() 
      shouldComposeBarFirstResponder = false 
     } 

     self.showMessageById(self.messageIdForMessageDisplay) 

     ChatCommonCall.sharedInstance.isChatModuleScreen = true 
     self.changeFrame() 
     self.composeBar.button.enabled = self.composeBar.text.trim().length > 0 ? true : false 
     /// Table frame changes. 
     switch self.optType 
     { 
     case .NewMessageSection: 
      break 
     case .DoNotHandle : 
      break 
     case .None : 
      if !(self.messageIdForMessageDisplay.isEqual(Guid.emptyGuid())) 
      { 
       self.optType = .ShowMessageOfID(id: self.messageIdForMessageDisplay) 
      } 
      else { 
       self.optType = .ScrollToBottom 
      } 
      break 
     default : 
      break 
     } 

     switch self.optType 
     { 
     case .NewMessageSection : 
      break 
     default : 
      self.handleOptType() 
     } 

     //Implemented the new observer pattern in the whole project where we suppose to refresh the screen for background sync data 
     //By Nikhil Kumar Saraf on 19 July 2016 
     Notifier.Unregister() 
     let observer = DatabaseObserverInfo(tName: ["chatthread","chatthreadmember","chatmessage","chatmessagereceiver","chatthumbnail","pfthumbnail","chatmessagemarker"], oType: [SyncOpType.Insert,SyncOpType.Update,SyncOpType.Delete], observer: self, stick: false, syncTrigger: SyncTriggerType.Post) 
     Notifier.Register(observer) 


     //By Balkrishan Yadav for AutoResizing UI on 30 Nov. 2016 
     NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(ChatMessageController.didChangePreferredContentSize(_:)), name:UIContentSizeCategoryDidChangeNotification, object: nil) 

     // This condition will execute if some one sharing image and coming to the chat message screen 
     //@Balkrishan Yadav 
     if ChatCommonCall.sharedInstance.attachmentInfo != nil { 
      self.addFileInComposeBar(ChatCommonCall.sharedInstance.attachmentInfo!) 
      ChatCommonCall.sharedInstance.attachmentInfo = nil 
      let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.3 * Double(NSEC_PER_SEC))) 
      dispatch_after(dispatchTime, dispatch_get_main_queue(), { 
       // your function here 
       // self.changeController(true) 
      }) 
     } 
    } 
} 
func handleOptType(callFromViewDidAppear:Bool = false) { 
     switch optType { 
     case .ScrollToBottom : // No new message is available. show last message.   self.messageTableView.setContentOffset(CGPointMake(0,CGFloat.max), animated: !isCameFromThreadComposer) 
      break 
     default: 
    // do nothing 
    } 
+0

你可以張貼一些代碼? – Jerry

回答

0

如果你不想滾動進行動畫,你只需要通過falseanimated參數滾動功能做。例如:

tableView.scrollToRow(at: indexPath, at: .top, animated: false) 

該函數將滾動indexPath的行表視圖的頂部沒有任何動畫。

+0

動畫標誌是假的,使用這種方法也會得到相同的結果。 –

+0

你可以顯示你正在滾動的代碼嗎?我找不到它在你的'executeCodeOfViewViewAppear'功能...... –

+0

請參閱方法 –