gpt4 book ai didi

ios - 有没有办法在保持同一页面的同时从 UIPageViewController 中更改标签文本?

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

我目前有一个 UIPageViewController,我需要它在完成 block 完成后更改文本,同时保持在同一页面上。我尝试这样做:

   func addChainedAnimationView (titleLabel: String, descriptionLabel: String){
//
(completion: {(finished) in
DispatchQueue.main.sync {
self.label1?.text = titleLabel

}
})
}

但我收到错误

EXC_ BAD_ INSTRUCTION

这就是 View Controller 的构建方式,它被缩短了,因此您可以忽略一些参数:

public class WelcomePageView : UIView
{
public var animationStrings : [String]?
public var titleStrings: [String]?
public var descriptionStrings: [String]?

var index: Int = 0
}

var label1 : UILabel?
var label2 : UILabel?

func buildViewControllerWithImage(titleString : String, titleString2 : String?, descriptionString: String, descriptionString2: String?, backgroundImage: String, jsonFile : String, jsonFile2 : String?, index : Int, loopCount: Int, userType: User, isLottieChained: Bool) -> UIViewController
{

let vc : UIViewController = UIViewController(nibName: "WelcomePageView", bundle: Bundle(for: type(of: self)))
(vc.view as? WelcomePageView)!.index = index
vc.view.frame = self.view.frame
var paragraphStyle = NSMutableParagraphStyle()

var label1String = titleString
if(!(label1String.contains("\n"))) {
label1String = "\n"+label1String
}
paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 0
paragraphStyle.alignment = .center
paragraphStyle.minimumLineHeight = 24
label1 = (vc.view.viewWithTag(2) as? UILabel)!
label1?.font = UIFont.CustomBold(size: 20)

var attrString = NSMutableAttributedString(string: label1String)
attrString.addAttribute(NSParagraphStyleAttributeName, value:paragraphStyle, range:NSMakeRange(0, attrString.length))
(vc.view.viewWithTag(2) as? UILabel)!.attributedText = attrString
return vc
}

我是这样得到它们的:

  func getViewControllerWithImage(_ index: Int, userType: User, country: Country) -> UIViewController

{
vc = self.buildViewControllerWithImage(titleString:"FIRST_SCREEN_TITLE".localized, titleString2: nil, descriptionString: "FIRST_SCREEN_DESCRIPTION".localized, descriptionString2: nil, backgroundImage: "fractal_blue", jsonFile: "Welcome_Step_01_V01", jsonFile2: nil, index: index, loopCount: loopCount, userType: userType, isLottieChained: false)

return vc
}

他们在这里被称为:

public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {

var index : Int = (viewController.view as? WelcomePageView)!.index // currentIndex = index

//currentIndex = index
//(viewController.view as? WelcomePageView)!.index

print ("XXXXX after \(index) XXXXXXX ")
//index = self.currentIndex
index += 1

if (index == maxPages)
{
index = 0
}
return self.getViewControllerWithImage(index, userType: User.newUser, country:

checkCountry())
}

最佳答案

我相信您的问题可能是在 DispatchQueue.main 上调用 sync 而不是 async

你已经在主队列中了,所以你永远不应该调用sync,因为它会导致主队列自身等待的死锁。

关于ios - 有没有办法在保持同一页面的同时从 UIPageViewController 中更改标签文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45355947/

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