I have a UIDatePicker in a view whose controller is in a UINavigationController. I'm registering changes in the selected date like this:
[self.datePicker addTarget:self.alarm action:#selector(timeChanged:) forControlEvents:UIControlEventValueChanged];
It works well, except if the user presses the back button in the UINavigationController before the date picker has completely settled. In that case, the timeChanged: method isn't being called, and so I'm not getting the new date.
Nothing is being released when I press the back button, it's just that the view controller is being popped off. (A reference to it is maintained).
I've found solutions to this problem with UIPickerView that involve implementing delegate methods for the picker view (eg: UIPickerView: Get row value while spinning?). But unless I'm very mistaken, that's not an option with a UIDatePicker. If possible, I'd like to stick with the UIDatePicker rather than a custom UIPickerView. Is there a way to do this? It doesn't have to get the selected row perfectly (within a row or two is fine), but the closer the better.
EDIT: This is for a jailbreak app, so private APIs are fine, if I can figure out what they are.
As for the current APIs, there's no way of detecting whether a UIDatePicker is spinning.
This is because UIDatePicker is not a subclass of UIPickerView and it manages a UIPickerView internally.
I'm afraid the best solution here is to use a custom UIPickerView.
Related
I am trying to create a reusable UIPickerView not unlike UIDatePicker for use in multiple table views. The view works great, but as it's delegate needs to be itself (in order to set the components and rows), I cannot implement the didSelectRow:inComponent: method (to update labels and the model) in the tableViewControllers it is being used in.
How can I subclass UIPickerView and still provide a delegate? If UIDatePicker can do it, I'm guessing there's a pretty straightforward way.
Inspecting the UIDatePicker, it is a subclass of UIControl and follows the target-action pattern. It appears Apple just adds a UIPickerView as a subview to the UIControl. UIDatePicker has made it since the original SDK, so I think I will stick with this method for creating a custom, self-contained PickerView.
More information on custom implementing a custom UIControl: http://www.raywenderlich.com/76433/how-to-make-a-custom-control-swift
I show EKCalendarChooser in popover. When user selects a calendar in the chooser I get its calendarIdentifier. Everything goes smooth till this point but When you reopen the popover the selection in the chooser disappears. How to maintain the selection or how to reselect the calendar again when user open the chooser popover again.
If EKCalendarChooser is normal UITableView I can easily match my db value with that of the displayed cell and make it selected. But here how do I set EKCalendarChooser tablecell selected? I do have the calendarIdentifier...any Ideas?
plz help me out.
Thanks in advance.
As the user works with the EKCalendarChooser, use the calendarChooserSelectionDidChange: delegate method to keep track as the user changes the selection. You can store the selectedCalendars property value each time this method is called.
Then, the next time the EKCalendarChooser appears, set its selectedCalendars property to the selection you previously saved.
Try to build a data layer to your application with reference to MVC design pattern see here.
Save the popover selection state (and the other data) at the data layer (model).
After that, access this data layer (model) each time u open the popover and configure the popover according the data.
Anyway, to to make cells selected or deselected in UITableViewDelegate methods:
tableView:didSelectRowAtIndexPath:
tableView:didDeselectRowAtIndexPath:
I have a UITableViewController that comes on to the screen in a popup. Basically it slides in from the left and shows the hierarchy available.
When it comes on screen, I select an item within it to represent the current location. Before today, this all worked.
Today I added a UITextView as a header to the table. Since then, my selection is acting strangely. When the UITableViewController appears, I can see my selected row get selected briefly, but it immediately becomes unselected. Calls to indexPathForSelectedRow return nil.
Is there a way to be alerted whenever the selection changes in UITableView? I know to use tableView:didSelectRowAtIndexPath: to keep track of when the user selects an item, but this problem is happening without user input. I'm assuming I've done something incorrect within the code, but I'm trying to track it down without posting all my code here.
Edit
Apropos of nothing, I did find that the problem goes away if I remove the Navigation Controller that I had added to the UITableViewController. This was because I had not set the property clearsSelectionOnViewWillAppear to NO. By adding the Navigation Controller, the UITableViewController was getting loaded differently, causing the property to actually be used.
However, I still would like to know how to be alerted to table view selection changes.
iOS Proficiency: Beginner
If I have a Xib with multiple fields that all need their own Picker View, what's an appropriate/canonical way to add multiple picker views on the page without getting the Design View all cluttered up?
1) Only add the PickerView programmatically and not via the XIB?
2) Use only 1 Picker object and populate it with different values based on the field
selection? (Possible memory benefits?)
3) Place the UIPickers on the View with a tiny height/width and then programmatically adjust height when necessary? Not even sure if the height is adjustable.
4)Combination of some of the above?
You can see in the image below, how cluttered it looks already even with just one picker view:
The view that you have with the text fields and picker views would lend itself to be part of a UITableView.
See the calendar app when you add an event.
You can set this up fairly easily by using a static UITableView.
I'm replying on my phone at the moment but will look for a tutorial if you would like.
If only one pickerView will be visible at once, then you should consider using only one pickerView and configure it's delegate/datasource so that you can give it a different datasource for each field.
Unless more than one is visible at once, there really isn't any reason to use more than one in your nib file. And even if you used more than one, you would still have to configure you delegate/datasource methods to handle each individual picker.
Hope that helps.
EDIT: It would be a little bit of work, but if you wanted the pickerView to animate in and out of the view whenever you need and if you wanted to clean your Xib up even more you could do the following:
Create a subview containing your pickerView
Set up a protocol on the subview to allow you to pass the selected value back to the view controller.
Set up your viewController to conform to the protocol on your picker subview.
Set the pickerView to be each textField's inputView.
Set the textField's delegate methods to configure the dataSource of your subview when editing begins.
By doing this, you have set your textField so that when it receives firstResponder that it will display the pickerView instead of a keyboard.
I wanted to use a UIPicker to simulate a drop-down menu and I found this code. It`s the second answer.
UIPickerView select and hide
Its exactly what I was locking for except for one thing. When I tap my TextField activating the method, like the author sais i should do, it takes a while for the UIPicker to show up. I would like to know if theres a way to make the code faster.
I think this happens because the method creates a UIPicker every time, but I`m not sure. Sorry if it is a stupid question.
Thanks
What I have done in the past is create the UIPickerView as a property of my UIViewController and then use the hidden property to display and dismiss it. You could even animate it up and down if you wanted to rather than just hide it. This way you will not be creating it every time. I could see how the creation would take a while if you are having to set it up with a lot of data or pulling the data from somewhere else.
So if I was you, I'd create it in viewDidLoad and then hide it until you are ready to use it instead of creating it each time. Or use an animation to take it on and off the screen.
One thing to remember, you are using the same UIPickerView each time, so you may want to set it up to some sort of default each time before you display it so it isn't just equal to whatever value they put in last upon display.
Likewise, I would create the toolbar and save it as a property as well and just hide or display both of them at the same time.