gpt4 book ai didi

swift - 使用快速自动布局滚动到 cellForRowAt Index 问题

转载 作者:行者123 更新时间:2023-11-30 12:43:01 33 4
gpt4 key购买 nike

我需要将表格滚动到底部。当我在 viewwilAppear 中编写滚动表格的代码时,它不起作用,但是当我在 viewDidAppear 中编写相同的代码时,它可以工作,但用户会看到滚动。我不想看到用户滚动如何在 ViewWillAppear 中使 tableScrolling。`

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
}

最佳答案

如果您不希望滚动有动画效果,则只需将 false 作为 animated 参数传递给滚动函数即可。例如:

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

此函数会将 indexPath 的行滚动到表格 View 的顶部,而不使用任何动画。

关于swift - 使用快速自动布局滚动到 cellForRowAt Index 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42022978/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com