gpt4 book ai didi

ios - 网点是零?

转载 作者:可可西里 更新时间:2023-10-31 23:56:24 25 4
gpt4 key购买 nike

我已经在 Storyboard中创建(并链接)了一些标签到标签,当我尝试修改文本时,我的应用程序抛出异常并卡住,因为它们显然是 nil

代码:

import UIKit

class QuoteView : UITableViewController {
@IBOutlet var quoteCategory: UILabel!
@IBOutlet var quoteTitle: UILabel!
@IBOutlet var quoteAuthor: UILabel!
@IBOutlet var quoteContent: UILabel!
@IBOutlet var quoteTimestamp: UILabel!
}

我试图在以前的 View Controller 的 prepareForSegue 方法中设置它们,如下所示:

overide func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
if (segue.identifier == "indivQuoteSegue") {
let svc = segue.destinationViewController as! QuoteView
let quote = quoteArray[(tableView.indexPathForSelectedRow?.row)!];
svc.quoteTitle.text = quote.getQuoteTitle()
svc.quoteAuthor.text = quote.getQuoteAuthor()
svc.quoteContent.text = quote.getQuoteContent()
svc.quoteCategory.text = quote.getCategory()
svc.quoteTimestamp.text = quote.getQuoteTimestamp()
}
}

最佳答案

prepareForSegue 中,你的导出还没有被初始化,所以你不能设置它们的属性。您应该创建 String 属性并设置它们,或者更好的是只传递您的 quote 对象。例如:

overide func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
if (segue.identifier == "indivQuoteSegue") {
let svc = segue.destinationViewController as! QuoteView
let quote = quoteArray[(tableView.indexPathForSelectedRow?.row)!];
svc.quoteTitleString = quote.getQuoteTitle()
svc.quoteAuthorString = quote.getQuoteAuthor()
svc.quoteContentString = quote.getQuoteContent()
svc.quoteCategoryString = quote.getCategory()
svc.quoteTimestampString = quote.getQuoteTimestamp()
}
}

然后在 QuoteViewviewDidLoad 中设置标签的文本

override func viewDidLoad(){
self.quoteTitle.text = self.quoteTitleString
etc...
}

关于ios - 网点是零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37081710/

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