我用谷歌搜索,但无法找出快速等同于什么respondsToSelector:.
这是我唯一能找到的东西(Swift替代respondsToSelector :)但在我的情况下并不太重要,因为它检查委托的存在,我没有委托我只想检查是否存在新的API或者不在设备上运行时,如果没有回到以前版本的api.
我的Swift-iOS应用程序旨在显示用户在地图上的位置.但是,XCode调试控制台告诉我,我需要请求权限才能显示用户的位置.我想,我这样做,但对话永远不会出现.
这是错误消息,在我调用的ViewController下面 CLLocationManager::requestWhenInUseAuthorization()
错误:
2014-06-30 21:25:13.927 RowingTracker2 [17642:1608253]尝试在不提示位置授权的情况下启动MapKit位置更新.必须首先调用 - [CLLocationManager requestWhenInUseAuthorization]或 - [CLLocationManager requestAlwaysAuthorization].
视图控制器:
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var mapview: MKMapView = nil
var locationmgr : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
locationmgr = CLLocationManager()
locationmgr.requestWhenInUseAuthorization()
mapview.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
如何申请授权使用该位置?你可以在这里 …
我以为自从Swift/ios8发布以来我在iOS开发中尝试过,我在构建基本的tableView时遇到了麻烦.
当前在模拟器中加载应用程序时收到以下错误消息(Xcode表示构建完成):
2014-06-11 13:40:56.173 firstapp[2217:85843] -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb20fcf0
2014-06-11 13:40:56.180 firstapp[2217:85843] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb20fcf0'
*** First throw call stack:
(
0 CoreFoundation 0x00452916 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01da28d9 objc_exception_throw + 44
2 CoreFoundation 0x004596f5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3 CoreFoundation 0x003a4857 ___forwarding___ + 1047
4 CoreFoundation 0x003a441e _CF_forwarding_prep_0 + 14
5 UIKit 0x00f149aa -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2767
6 UIKit 0x00f18ebc …Run Code Online (Sandbox Code Playgroud)