swift2

Swift Search Result Controller in search results segue to another view controller

淺唱寂寞╮ 提交于 2020-01-13 05:27:29
问题 Problem: I have a table view that the user can either scroll through to find something or use a search bar. The search bar was not created using the StoryBoard. My view has a UISearchController that handles the search bar and search result updating. The issue that I'm running into is that since my SearchResultsController is instantiated by another controller I cannot perform a segue to another view, or at least I can't find the solution. Everything works except for the segue between my Search

Swift 2 unused constant warning

丶灬走出姿态 提交于 2020-01-12 23:16:32
问题 I am getting a warning saying my constant is unused: Initialization of immutable value 'myConst' was never used; consider replacing with assignment to '_' or removing it if someVal["value"] != nil { let myConst = someVal["value"] } So what will renaming let myConst = someVal["value"] into _ myConst = someVal["value"] do/mean? 回答1: You're not replacing let with _ , but you're replacing the variable name with it. If the variable isn't used anywhere in the code it's irrelevant so the line can be

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

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)

How to Save ReplayKit Video to Camera Roll with In-App Button

五迷三道 提交于 2020-01-12 03:19:08
问题 I am relatively new to iOS development and Swift but I have an app I'm working on which is supposed to record the activity on the screen and save the resulting video to the camera roll. I am using ReplayKit. What is working now: This is the code I have beginning the recording and ending the recording the startRecording() function is run by a button that says "start" and the stopRecording() function is called by a button that says "stop". var preview : RPPreviewViewController? func

Default parameter values error: “instance member cannot be used on type viewcontroller”

杀马特。学长 韩版系。学妹 提交于 2020-01-11 11:04:59
问题 In my view controller: class FoodAddViewController: UIViewController, UIPickerViewDataSource, UITextFieldDelegate, UIPickerViewDelegate { let TAG = "FoodAddViewController" // Retreive the managedObjectContext from AppDelegate let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext @IBOutlet weak var foodName: UITextField! @IBOutlet weak var foodPortion: UITextField! @IBOutlet weak var foodCalories: UITextField! @IBOutlet weak var foodUnit:

Go back to previous view controller doesn't work

末鹿安然 提交于 2020-01-11 06:45:14
问题 My first view controller has a button, which triggers the @IBAction goTo2ndVc() which presents a second ViewController: class FirstVC: UIViewController { ... @IBAction func goTo2ndVc() { let secondVc = SecondVC(label: "I am second vc.") self.presentViewController(secondVc, animated: true, completion: nil) } When the button is pressed, the 2nd view controller is shown on screen. No problem. In 2nd view controller, there is also a button which is used to go back to 1st view controller: class

Error with Parse Query findObjectsInBackgroundWithBlock

依然范特西╮ 提交于 2020-01-11 05:41:08
问题 I am new to ios development and I recently found a tutorial to build a tweeter like ios app using a parse backend. My current set up is Xcode 7.1 with swift 2.0, the tutorial was done on an older version of swift so I had to adjust some of the swift syntax in order to make it work. I was doing fine until I hit the following error, func loadData(){ timelineData.removeAllObjects() var findTimelineData:PFQuery = PFQuery(className: "Tweet") findTimelineData.findObjectsInBackgroundWithBlock{

How can I get the migration to run before the app starts to run the code?

吃可爱长大的小学妹 提交于 2020-01-11 05:20:09
问题 I'm using realm.io in a swift app. This is the first time I've had to run a migration since I have an app in production. I changed one of the models and added a couple of extra fields to it. I followed the example in the documentation and then referenced the github repo's example when that didn't work. I assumed that it was probably more complex then what the example in the documentation was letting on. Here's what I have in my appdelegate.swift file: func application(application:

My data changes in UITableViewCell when I scroll down and get back

浪尽此生 提交于 2020-01-10 19:59:42
问题 When I'm populating new data in my tableView Controller, my top cell is being rewrite by the bottom one. Let me explain. I have one image that is loading async in the latest cell row, in the bottom. All the other cells are loading static with an image that is in the app. When I scroll down my app and display my bottom cell which have a different image than the others cells, and I scroll up again, I see the first shop image has changed to the dynamic one loaded in the bottom cell. Does anyone