Tag: 快速

Swift协议只能设置?

为什么我可以做到这一点没有任何错误: var testDto = ModelDto(modelId: 1) testDto.objectId = 2 而我定义这个: protocol DataTransferObject { var objectType: DtoType { get } var parentObjectId: Int { get set } var objectId: Int { get } var objectName: String { get set } } struct ModelDto: DataTransferObject { var objectType: DtoType var parentObjectId: Int var objectId: Int var objectName: […]

Swift addsubview并将其删除

我想添加子视图,并删除一个水龙头。 这是我的代码: / *添加子视图* / var testView: UIView = UIView(frame: CGRectMake(0, 0, 320, 568)) testView.backgroundColor = UIColor.blueColor() testView.alpha = 0.5 testView.tag = 100 super.view.userInteractionEnabled = false self.view.userInteractionEnabled = true self.view.addSubview(testView) / *删除子视图* / override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject() as UITouch let point = touch.locationInView(self.view) if(testView.tag==100){ println("Tag 100") testView.removeFromSuperview() […]

如何使用Apple Map Kit实现地址的自动填写

我想自动完成用户的地址,就像google api在这个链接中提供的一样: https://developers.google.com/maps/documentation/javascript/places-autocomplete?hl=en 我如何使用苹果地图工具包实现相同的function? 我试图使用地理编码器,我写这个例如: @IBAction func SubmitGeoCode(sender: AnyObject) { let address = "1 Mart" let coder = CLGeocoder() coder.geocodeAddressString(address) { (placemarks, error) -> Void in for placemark in placemarks! { let lines = placemark.addressDictionary?["FormattedAddressLines"] as? [String] for addressline in lines! { print(addressline) } } } } 但结果非常令人失望。 任何苹果API可用于实现这样的function,或者我应该头谷歌API? 谢谢

当应用程序从iOS中的本地通知进入前景时触发特定的操作? (使用swift)

我正在使用新的语言Swift构build一个iOS应用程序。 现在它是一个HTML5应用程序,它使用UIWebView显示HTML内容。 该应用程序有本地通知,而我想要做的就是在应用程序通过点击(触摸)本地通知进入前景时在UIWebView中触发一个特定的javascript方法。 我已经看过这个问题 ,但似乎并没有解决我的问题。 我也遇到这个问题 ,告诉我使用UIApplicationState,这是好的,这将帮助我知道应用程序从通知进入前台。 但是,当应用程序恢复,如何调用应用程序恢复时显示的视图的viewController中的方法? 我想要做的是得到我的ViewController的一个实例,并在其中设置一个属性为true。 如下所示 class FirstViewController: UIViewController,UIWebViewDelegate { var execute:Bool = false; @IBOutlet var tasksView: UIWebView! } 而在我的AppDelegate我有方法 func applicationWillEnterForeground(application: UIApplication!) { let viewController = self.window!.rootViewController; let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("FirstView") as FirstViewController setViewController.execute = true; } 所以我想要做的是当应用程序再次进入前台时,我想查看执行variables并运行方法如下, if execute{ tasksView.stringByEvaluatingJavaScriptFromString("document.getElementById('sample').click()"); } […]

我如何自动滚动表格视图? (迅速)

我添加了一个search栏到我的表格视图,当用户search,我希望表视图滚动到您键入的文本。 如何使滚动视图自动滚动? 这是我尝试,但我得到一个错误,说一个整数不能转换为索引path。 我该怎么办? self.tableview.scrollToRowAtIndexPath(1, atScrollPosition: UITableViewScrollPosition.Middle, animated: true) 要么 self.tableview.scrollToNearestSelectedRowAtScrollPosition(scrollPosition: UITableViewScrollPosition.Middle, animated: true)

将数据源分隔到Swift中的另一个类

我试图保持我的视图控制器干净,如本文所述objc.io问题#1更轻的视图控制器 。 我在Objective-C中testing了这个方法,它工作正常。 我有一个单独的类实现UITableViewDataSource方法。 #import "TableDataSource.h" @interface TableDataSource() @property (nonatomic, strong) NSArray *items; @property (nonatomic, strong) NSString *cellIdentifier; @end @implementation TableDataSource – (id)initWithItems:(NSArray *)items cellIdentifier:(NSString *)cellIdentifier { self = [super init]; if (self) { self.items = items; self.cellIdentifier = cellIdentifier; } return self; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.items.count; } – (UITableViewCell *)tableView:(UITableView […]

检查UIAlertController TextField是否启用button

我有一个AlertController与文本字段和两个button:取消和保存。 这是代码: @IBAction func addTherapy(sender: AnyObject) { let addAlertView = UIAlertController(title: "New Prescription", message: "Insert a name for this prescription", preferredStyle: UIAlertControllerStyle.Alert) addAlertView.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil)) addAlertView.addAction(UIAlertAction(title: "Save", style: UIAlertActionStyle.Default, handler: nil)) addAlertView.addTextFieldWithConfigurationHandler({textField in textField.placeholder = "Title"}) self.presentViewController(addAlertView, animated: true, completion: nil) } 我想要做的是实现一个文本框检查当禁用保存button,当文本框是空的就像图片应用程序的iOS,当你想创build一个NewAlbum。 请有人能解释我该怎么做?

如何快速打开和closures手电筒?

我想在Swift中将手电function添加到我的应用程序中。 我怎么能这样做呢?

ios中block(Objective C)和closure(Swift)之间的区别

在教程中,它的function都相同,即使闭包更容易,然后阻止和它避免了块和内存pipe理的复杂性,我已经经历了许多教程,但除了这些我没有得到区别之间的swift的“封闭” Objective-C“块”。 任何人都可以深入解释这种差异。 任何帮助,将不胜感激。

如何找出坐标之间的距离?

我想让它显示两个CLLocation坐标之间的距离。 有没有一个复杂的math公式做到这一点? 如果没有一个公式你会怎么做?