swift2

How to do number keypad with done button in Swift 2.0?

时光毁灭记忆、已成空白 提交于 2019-12-23 02:59:19
问题 I've tried lots of numeric keyboard with done button, it's not found a correct answer in SWIFT 2.0. 回答1: You can add done button above keyboard using toolbar override func viewDidLoad() { super.viewDidLoad() let tooBar: UIToolbar = UIToolbar() tooBar.barStyle = UIBarStyle.BlackTranslucent tooBar.items=[ UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: self, action: nil), UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action:

Black screen when launching the app on device since XCode7 update

一世执手 提交于 2019-12-23 02:43:12
问题 I've updated XCode7 and like everyone, i have to amend a part of my code to be compliant with Swift2. But i have a problem, when i m testing the app on the simulator i have no problem. But when i m trying directly on my real device (Iphone 5S IOS9), a black screen displays just with the level of the battery. I have tried during 3 days to find something on stackoverflow, but nothing seems working. This topic seems to be the same problem, but doen't work actually. IOS 7 launch image, displaying

UIDatePicker crashing application

丶灬走出姿态 提交于 2019-12-23 01:51:09
问题 In my app I have a textfield form that i want populated from a date picker, I have assigned the date picker as the input view for the textfield and a datePickerValueChanged func to change the text of the textfield when the picker is changed. My issue is that when clicking off the data picker in the app, the whole app crashes with 'terminating with uncaught exception of type NSException' any ideas? Here is my code: @IBOutlet var startDatePickerField: UITextField! override func viewDidLoad() {

Intercom.io Custom Attributes for Swift aren't working

做~自己de王妃 提交于 2019-12-23 01:34:06
问题 I'm trying to implement custom attributes for Intercom.io into my iOS app. I'm in XCode 7, Swift 2 and iOS 9. Here's my code: class func updateUser(user: User) { Intercom.updateUserWithAttributes([ "name": user.name, "email": user.email ]) let userAttributes = ([ "role": "customer", "phone": user.phone, "First Name": user.firstName, "Last Name": user.lastName, "Referral Code": user.referralCode, "Avatar Pic": user.avatarURL, "Profile Pic": user.profilePicURL ]) Intercom

Not able to pass self (which implements a protocol) to init method of a class instantiation.(Swift)

杀马特。学长 韩版系。学妹 提交于 2019-12-23 01:12:09
问题 I have a protocol like so public protocol FooProtocol { associatedType someType func doFoo(fooObject:someType) -> Void } I have a class that implements this protocol public class Foo<T> : FooProtocol { private let _doFoo : (T) -> Void init<P : FooProtocol where P.someType == T>(_dep : P) { _doFoo = _dep.doFoo } public func doFoo(fooObject: T) { _doFoo(fooObject) } } Everything upto here looks good to me, Now in another class I implement the FooProtocol with someType = MyType , then when I try

Change the orientation only for specific view controllers in ios swift 2.3 and swift 3

。_饼干妹妹 提交于 2019-12-23 00:52:11
问题 I was searching that how can I change the orientation to LandScape mode only for spefic view controller when the Device Orientation is set to Portrait in the project settings . Didn't get any succesfull result. so finally I found a way to do it. this is project device orientation looks like .... In swift 2.3 add following methods override func shouldAutorotate() -> Bool { return false } override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { return

How to use NSRegularExpression in Swift 2.0 in xcode 7

你离开我真会死。 提交于 2019-12-22 18:21:10
问题 //The error is here let regex = NSRegularExpression(pattern: "(<img.*?src=\")(.*?)(\".*?>)", options: nil, error: nil) //The error is:*** cannot find an initializer for type nsregularexpression that accept an argument of type (pattern: string,ption:nil,error:nil) 回答1: There are 2 changes with regards to the syntax in Swift 2.0: (1) you wrap the call in a try ... catch block instead of supplying an error parameter; and (2) options should be a Set , not a numerical or of the individual options.

Making table view section expand swift

痴心易碎 提交于 2019-12-22 17:05:13
问题 I am following this tutorial for expanding and collapsing my table view section. As this demo is done in swift 2.2 I have made all the changes according to swift 3.0 . I am stuck at the below function at if condition(currentSectionCells[row]["isVisible"]) which gives me error as "Type 'NSFastEnumerationIterator.Element' (aka 'Any' has no subscript members)'". func getIndicesOfVisibleRows() { visibleRowsPerSection.removeAll() for currentSectionCells in cellDescriptors { var visibleRows = [Int]

Alamofire and SwiftyJSON for Swift 2.0

北战南征 提交于 2019-12-22 13:58:53
问题 I am updating my code for Swift 2.0 for today, however the line var json = JSON(json) gives me the following error Cannot invoke intializer for type 'JSON' with an argument list of type (Result) Do you guys have any idea how should I change my code? @IBAction func changePassword(sender: UIBarButtonItem) { Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm

UIActivityViewController on iPad

女生的网名这么多〃 提交于 2019-12-22 13:58:45
问题 I have been using the code below to show a UIActivityViewController which worked fine when I was using Xcode 6, Swift 1.2 and iOS 8. However when I updated it shows the UIActivityViewController but it is completely blank without any of the sharing options. Do you have any suggestions? if UIDevice.currentDevice().userInterfaceIdiom == .Pad { let textToShare = textViewOne.text let objectsToShare = [textToShare] let activityVC = UIActivityViewController(activityItems: objectsToShare,