swift3

Hide button in Swift 3

試著忘記壹切 提交于 2020-01-13 08:18:53
问题 I've just started with coding and I really want to know how to hide buttons. What I want to do is when I press my button: Start: I want to let the start button and the back button disappear. It's done with Outlets and Actions. I already searched a bit but when I wanted to do it, it said that the do keyword is expected to designate a block of statements. I hope someone can help me out. 回答1: Once you have your outlets connected, simply change the isHidden property to true. IBOutlet weak var

Perform Selector With Object in swift 3

烂漫一生 提交于 2020-01-13 07:36:06
问题 I am trying to perform selector with object in swift 3.0 I have a selector which have one parameter func imageSelected(aImage : UIImage) and I am calling it like viewC.perform(Selector.init("imageSelected:"), with: image, afterDelay: 0.1) But the app crashes with error that the selector is not defined. 回答1: Here's something I always do when I encounter selectors in swift: Ignore the parameters, just use the name. You used this: imageSelected: What is that : doing there? Delete it! Just use

Phone number format from country code on iOS

佐手、 提交于 2020-01-13 06:53:29
问题 I need to display phone number format as placeholder in UITextField . How can I do that? For country selection I'm using below mentioned library and it provides me country flag and country code against user selected country. https://github.com/NikKovIos/NKVPhonePicker After selecting a country I need to display phone number format for that selected country and on submission of that phone number I have to validate the phone number. I also find that third party ( PhoneNumberKit ) which is

Today Extension with UICollectionView different behaviour compared to Single View Application

半世苍凉 提交于 2020-01-13 01:40:22
问题 I try to add a collection view to a Today Extension with specifying the items per row of 3 items and also with setting the section insets for with 20 for top, left, bottom and right. When I do this in a Single View Application everything is like expected, but when I do the same programmatically for the Today Extension the collection view looks different, especially the space of the right and bottom seems not to be like in the Single View Application. What's the reason why there is this

How to center align the cells of a UICollectionView in Swift3.0?

天大地大妈咪最大 提交于 2020-01-12 14:04:18
问题 Description: Answer for Objective-C and Swift2.0 : How to center align the cells of a UICollectionView? I usually would try to convert the Swift2.0 answer to the Swift3.0 solution, however the method: func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { let edgeInsets = (screenWight - (CGFloat(elements.count) * 50) - (CGFloat(elements.count) * 10)) / 2 return UIEdgeInsetsMake(0,

How to add buttons above keyboard

混江龙づ霸主 提交于 2020-01-12 11:06:11
问题 How to add button above the keyboard like this one in Stack Exchange app? And when you long press the text in UITextView How to add "Select" and "Select All"? 回答1: The first question, you can set textField 's inputAccessoryView to your custom view, this can customize the keyboard's header. The result: You can do it like below; first, you should instance the view you want to add above the keyboard. class ViewController : UIViewController { @IBOutlet weak var textField: UITextField! override

I want to change the sample rate from my input node from 44100 to 8000

点点圈 提交于 2020-01-12 09:52:52
问题 I want to read the buffer from my microphone into an array, with 441khz its working fine but with the sample rate 8khz it comes to an error ERROR: >avae> AVAudioIONodeImpl.mm:884: SetOutputFormat: required condition is false: format.sampleRate == hwFormat.sampleRate 2016-11-26 19:32:40.674 Atem[5800:1168274] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == hwFormat.sampleRate' with my following code : var

I want to change the sample rate from my input node from 44100 to 8000

折月煮酒 提交于 2020-01-12 09:52:28
问题 I want to read the buffer from my microphone into an array, with 441khz its working fine but with the sample rate 8khz it comes to an error ERROR: >avae> AVAudioIONodeImpl.mm:884: SetOutputFormat: required condition is false: format.sampleRate == hwFormat.sampleRate 2016-11-26 19:32:40.674 Atem[5800:1168274] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == hwFormat.sampleRate' with my following code : var

can not convert value type “string?” to expected argument type “inout string”

只谈情不闲聊 提交于 2020-01-12 07:26:59
问题 this line self.displayResultLable.text += (title as! String) error throwing can not convert value type "string?" to expected argument type "inout string" Here is my code : if results.count > 0 { var displayResult : String? for books in results as! [NSManagedObject] { if let title = books.valueForKey("title") { self.displayResultLable.text += (title as! String) } } } what is the inout string here ? what is the best practice ? Note this line self.displayResultLable.text = (title as! String)

“NSURL” is not implicitly convertible to “URL”; did you mean to use “as” to explicitly convert?

女生的网名这么多〃 提交于 2020-01-12 06:42:07
问题 I have latest xcode beta, just trying to load a webpage inside an app. import UIKit class ViewController: UIViewController { @IBOutlet var webView: UIWebView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let url = NSURL (string: "https://www.google.com"); let requestObj = NSURLRequest(URL: url!); webView.loadRequest(requestObj); } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose