我的应用是基于导航的。UIBarButtonItem 就可以了。
refreshstopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self
action:@selector(refreshTapped)];
我发现当我点击状态栏时,“refreshTapped”被触发(不是由我的大手指引起的,也可以通过使用模拟器和鼠标单击来重现)。Stacktrace 显示它来自
-[UIApplication sendAction:to:from:forEvent:];
我不明白为什么。有时我的应用程序崩溃,堆栈跟踪与iPhone 上的崩溃非常相似?
注意:我也尝试了 UICatalog 示例,我看到了同样的事情:单击状态栏会触发“返回”UIBarButtonItem 操作(使用模拟器)。
玩了一段时间模拟器后,我意识到敏感区域比按钮边框大得多。我想也许这就是 Cocoa Touch 的工作方式。
然而,崩溃问题仍未解决。根据堆栈跟踪,看起来它是由触摸状态栏触发的。
这是崩溃日志:
0 libobjc.A.dylib 0x32da1cb2 objc_msgSend + 42
1 UIKit 0x324c3a30 -[UIControl(Deprecated) sendAction:toTarget:forEvent:] + 28
2 UIKit 0x324c3990 -[UIControl(Internal) _sendActionsForEventMask:withEvent:] + 352
3 UIKit 0x32563764 -[UIControl mouseUp:] + 376
4 UIKit 0x3254d314 -[UIView(Internal) _mouseUp:] + 32
5 UIKit 0x3254a480 -[UIWindow _handleMouseUp:] + 108
6 UIKit 0x3254a8da -[UIWindow _statusBarMouseUp:] + 122
7 UIKit 0x32680980 -[UIStatusBar touchesEnded:withEvent:] + 320
8 CoreFoundation 0x328d056a -[NSObject(NSObject) performSelector:withObject:withObject:] + 18
9 UIKit 0x32406094 forwardMethod2 + 60
10 UIKit 0x324a04ca -[UIResponder touchesEnded:withEvent:] + 2
11 UIKit 0x32404bee -[UIWindow _sendTouchesForEvent:] + 362
12 UIKit 0x32404568 -[UIWindow sendEvent:] + 256
13 UIKit 0x323ed30c -[UIApplication sendEvent:] + 292
14 UIKit 0x323ecc4c _UIApplicationHandleEvent + 5084
我还尝试按照http://cocoawithlove.com/2009/05/intercepting-status-bar-touches-on.html在状态栏上捕获事件。但正如其他人指出的那样,它不再适用于 iOS 4.x