gpt4 book ai didi

ios - 使用 let buttonPosition = sender.convertPoint(CGPointZero, toView : self. tableView) 点击时更改 TableViewCell 中 UIButton 的标题

转载 作者:行者123 更新时间:2023-11-30 14:09:40 24 4
gpt4 key购买 nike

在这里,我从 Parse 检索了数据,并在 tableViewCell 中显示该数据。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("users", forIndexPath: indexPath) as! userListTableViewCell

let userData:PFObject = self.data.objectAtIndex(indexPath.row) as! PFObject

// Usernames and gender..

myCell.fullName.text = userData.objectForKey("fullName") as! String!
myCell.genderLabel.text = userData.objectForKey("gender") as! String!

// Profile pictures..

let profilePics = userData.objectForKey("profilePicture") as! PFFile
profilePics.getDataInBackgroundWithBlock { (data, error) -> Void in

if let downloadedImage = UIImage(data: data!) {

myCell.dp.image = downloadedImage
}

}

myCell.followButtton.addTarget(self, action: "followButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside)



return myCell
}

现在我已经申请了UIButtonUITableViewCell成功了,我通过这种方式很好地获得了坐标:

// IBActions..


func followButtonTapped(sender:AnyObject) {
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition)
if indexPath != nil {



println(indexPath)


}
}

现在,当用户点击任何按钮时,我想更改该按钮的标题。感谢您抽出时间......如果这是我问的基本问题,我很抱歉,我是初学者。

这就是点击按钮时我得到的结果..

<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}
<NSIndexPath: 0xc000000000010016> {length = 2, path = 0 - 2}

我可以使用这个吗?

func followButtonTapped(sender:AnyObject) {
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition)
if indexPath != nil {

sender.setTitle("title", forState: UIControlState.Normal)

println(indexPath)


}
}

..我愿意接受任何类型的答案..任何更好的方法也会被接受..

最佳答案

func followButtonTapped(sender:AnyObject) {
let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition)
if indexPath != nil {

if let cell = tableView.cellForRowatindexPath(indexPath){
cell.followButton.setTitle("input title here")
}


println(indexPath)


}
}

关于ios - 使用 let buttonPosition = sender.convertPoint(CGPointZero, toView : self. tableView) 点击时更改 TableViewCell 中 UIButton 的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31897107/

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