我有一个UIView,并且我已添加了点击手势:
let tap = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
tap.delegate = self
myView.addGesture(tap)
Run Code Online (Sandbox Code Playgroud)
我试图在testfile中以编程方式调用它.
sendActionForEvent
Run Code Online (Sandbox Code Playgroud)
我正在使用此功能,但它无法正常工作:
myView.sendActionForEvent(UIEvents.touchUpDown)
Run Code Online (Sandbox Code Playgroud)
它显示发送到实例的无法识别的选择器.
我怎么解决这个问题?
提前致谢
我有一个带有几个IBOutlets的自定义单元类.我已将该课程添加到故事板中.我连接了所有的插座.我的cellForRowAtIndexPath函数如下所示:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SwipeableCell
cell.mainTextLabel.text = self.venueService.mainCategoriesArray()[indexPath.row]
return cell
}
Run Code Online (Sandbox Code Playgroud)
这是我的自定义单元类:
class SwipeableCell: UITableViewCell {
@IBOutlet var option1: UIButton
@IBOutlet var option2: UIButton
@IBOutlet var topLayerView : UIView
@IBOutlet var mainTextLabel : UILabel
@IBOutlet var categoryIcon : UIImageView
init(style: UITableViewCellStyle, reuseIdentifier: String!) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我的所有单元格都是空的.我已经注销self.venueService.mainCategoriesArray(),它包含所有正确的字符串.我也试过把一个实际的字符串等于标签,这会产生相同的结果.
我错过了什么?任何帮助表示赞赏.
我有一个包含UILabel和UIImageView的自定义UIView.如何使我的UIView可点击?我想在用户开始按下UIView的任何时候改变UIView的背景.当用户抬起按钮时,颜色应该会改变.我还需要能够处理click事件.
任何人都知道如何删除UIButton由于辅助功能而出现的下划线?
(我知道这是因为用户打开了"按钮形状")

如何以编程方式删除它,或通过在Xcode中设置一些属性?
在我看来,我想添加一个目标,当我点击视图时应该触发该目标.我可以通过IB做同样的事情,或者我甚至在代码中为按钮做了这件事.但是我不知道如何以编程方式为UIView做这件事.
任何人之前都这样做过.
帮我.
我试图将我在Storyboard中创建的UIView用作按钮。我认为可以使用UIButton,将类型设置为custom。但是,我无法将子视图添加到情节提要中的自定义UIButton。
因此,我刚刚花了最后一个小时,通过制作自己的自定义手势识别器来重新实现按钮功能,从而彻底改变了方向盘。
当然,这不是最好的方法,所以我的问题-比我自己更有经验的iOS开发人员-制作自定义按钮的最佳方法是什么?
为了清楚起见,它需要:
谢谢您的帮助。
我有视图,我想在其中执行向右滑动手势.不幸的是我收到错误EXC_BAD_ACCESS.有人知道这里有什么问题吗?请看下面的代码.
extension UIView {
func addGestureRecognizerWithAction(nizer: UIGestureRecognizer, action:() -> ()) {
class Invoker {
var action:() -> ()
init(action:() -> ()) {
self.action = action
}
func invokeTarget(nizer: UIGestureRecognizer) {
self.action()
println("Hi from invoker")
}
}
addGestureRecognizer(nizer)
nizer.addTarget(Invoker(action), action: "invokeTarget:")
}
}
class BugView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
var swipeRight = UISwipeGestureRecognizer()
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.addGestureRecognizerWithAction(swipeRight) {
println("Hi from the gesture closure")
}
}
}
Run Code Online (Sandbox Code Playgroud) ios ×5
cocoa-touch ×3
swift ×3
uiview ×3
ios8 ×2
iphone ×2
uibutton ×2
ios5 ×1
ios6 ×1
ios7.1 ×1
objective-c ×1
storyboard ×1
uiimageview ×1
uilabel ×1
uitableview ×1