gpt4 book ai didi

ios - 如何更改按钮上的操作目标 - Swift

转载 作者:行者123 更新时间:2023-11-30 13:47:01 25 4
gpt4 key购买 nike

import Foundation
import MapKit

class CustomAnnotationView : MKPinAnnotationView
{
let selectedLabel:UILabel = UILabel.init(frame:CGRectMake(0, 0, 250, 125))
let Button:UIButton = UIButton.init(frame:CGRectMake(0, 0, 100, 38))

override func setSelected(selected: Bool, animated: Bool)
{
super.setSelected(false, animated: animated)

if(selected)
{
selectedLabel.text = annotation!.title!
selectedLabel.center.x = 0.5 * self.frame.size.width
selectedLabel.center.y = -0.5 * selectedLabel.frame.height

self.addSubview(selectedLabel)

Button.backgroundColor = UIColor.yellowColor()
Button.setTitle("Press", forState: UIControlState.Normal)


//the code below here //
var storyboard = UIStoryboard(name: "Main", bundle: nil)
let Map = storyboard.instantiateViewControllerWithIdentifier("Map")
Button.addTarget(Map, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)

//self.view.addSubview(button)
Button.center.x = 0.5 * self.frame.size.width + 10
Button.center.y = selectedLabel.center.y
self.addSubview(Button)

}
else
{
selectedLabel.removeFromSuperview()
}

}

//Map.swift 中的这个

    func buttonAction () {
print("button pressed")
}
}

而不是使用 Button.addTarget(self...当我在自定义类中编码时。我如何让它运行该操作?我还将 Storyboard的名称设置为右侧面板上的 Main,与 map 的名称相同。

最佳答案

调用setSelected方法后,Map被释放。您应该通过某些东西(属性,全局变量,...)来处理Map

关于ios - 如何更改按钮上的操作目标 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34803584/

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