gpt4 book ai didi

ios - 将单元格名称传递给 View Controller 旁边

转载 作者:行者123 更新时间:2023-11-30 13:44:49 29 4
gpt4 key购买 nike

首先,感谢您阅读我的问题!

因此,我遇到了一些有关将单元格名称传递到下一个 View 的问题。现在它会传递它,但只会显示最近加载的单元格。

现在的编程方式如下:

var passName = ""
var passAuthor = ""
var passLikes = 0
var passDescrip = ""

required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!

// Configure the PFQueryTableView
self.parseClassName = "Location"
self.textKey = "Name"
self.pullToRefreshEnabled = true
self.paginationEnabled = true
self.objectsPerPage = 5

}
override func queryForTable() -> PFQuery {
let query = PFQuery(className: "Location")
query.orderByAscending("Name")
return query
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> CustomPFTableViewCell {

let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomPFTableViewCell!

print("Loading Parse Database Files...")
// Extract values from the PFObject to display in the table cell
if let name = object?["Name"] as? String {
cell?.nameTextLabel?.text = name
passName = name
print("Loading " + name)
}
if let author = object?["authorName"] as? String {
cell?.authorTextLabel?.text = author
passAuthor = author
}
if let likes = object?["Likes"] as? Int {
let stringVal = String(likes)
cell?.numLikes.text = stringVal
passLikes = likes
}
if let descrip = object?["Description"] as? String {
passDescrip = descrip

}
let initialThumbnail = UIImage(named: "Unloaded")
cell.customFlag.image = initialThumbnail
if let thumbnail = object?["imageCover"] as? PFFile {
cell.customFlag.file = thumbnail
cell.customFlag.loadInBackground()


}
print("Finished loading!")


return cell
}

//Original prepareForSegue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "toDetailScene") {

// initialize new view controller and cast it as your view controller
let viewController = segue.destinationViewController as! DetailViewController




viewController.tripName = passName
viewController.tripAuthor = passAuthor
viewController.tripLikes = passLikes
viewController.tripDescrip = passDescrip
}
}

稍后,下一个 View Controller 使用以下简单代码接收它: @IBOutlet 弱变量名称:UILabel! @IBOutlet 弱变量喜欢:UILabel! @IBOutlet 弱变量作者:UILabel! @IBOutlet 弱变量描述:UITextView!

var currentObject : PFObject?

var tripName = ""
var tripAuthor = ""
var tripLikes = 0
var tripDescrip = ""

override func viewDidLoad() {
super.viewDidLoad()



//Hookup
name.text = tripName
likes.text = String(tripLikes)
author.text = tripAuthor
descrip.text = tripDescrip

}

我需要修复它,这样它就不会一直尴尬地显示错误的文章/信息。

如果我可以简单地拉出他们单击的正确单元格,那么我可以从每个标签中拉出文本吗?那么我怎样才能获得正确的细胞呢?

顺便说一句:它通过 show segue 从单元格转移到下一个 View Controller 。 (在导航 Controller 中)

非常感谢!

最佳答案

@Paulw11 在评论中回答了这个问题,它解决了我的问题。

发件人:AnyObject?允许我添加:

let cell = sender as! CustomPFTableViewCell

然后我所要做的就是更新方法以直接从单元格连接文本字段的新值。

这是代码:

let viewController = segue.destinationViewController as! DetailViewController         
let cell = sender as! CustomPFTableViewCell

viewController.tripName = cell.nameTextLabel.text!
viewController.tripAuthor = cell.authorTextLabel.text!
viewController.tripLikes = Int(cell.numLikes.text!)!

关于ios - 将单元格名称传递给 View Controller 旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35095039/

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