How to make a picker view dynamically in Xcode in objective c? - ios

I am newbie in iOS.I a trying to make picker view in a navigation toolbar my dates are coming their sucessfully.I need to make a Picker view which fills datasource with 2 names and on selection of it i need to return it in string so that I can apply a sql query on it.
I have already mentioned the method of picker view for making my dates come their.
The issue is that I need picker views one which selects the date and other which shows 2 name For e.g 1)Emergency 2)Synergy11.I need to fill both in the picker view. Please let me know.

Related

How to achieve calendar week view in swift iOS

How can I achieve week view of the calendar in my iOS app as shown below, ideally using Apple calendar components (if any) and also how can I retrieve the selected date.
I have tried using both FSCalender and CVCalender plugins, without much success, as each was missing one element or the other.
The answer is, you lay out a bunch of views and set their contents. Perhaps use a collection view for the horizontal days. Definitely use a table view for the times. There's nothing in the public SDK to do it all for you. You just put together a view hierarchy the normal way.

How to add an image next to picker view entries?

As illustrated in this picture, I need to add an image next to my picker view entries, it's a picker view that is added to a UITextfield, what is needed is adding an image in place of the blue triangle, an image next to each option, how to do this?
I found solutions for this in objective-C, but found nothing for swift.
I will pick the first answer as the answer for this question and vote up for any useful comment..
Thanks.
With a picker view you either provide a title for each item, or a custom view for each item. If you want an image combined with text you should provide a custom view.
You need to implement the pickerView:viewForRow:forComponent:reusingView: method in your picker's data source. You'll need to provide a view that contains an image view and a label. You can either create that in code or load a new one from an XIB file each time you need to create one. I don't have any ready-made code for you, but this isn't that difficult.

How to pass date into picker view in ios

I just want to pass date in to picker view and other next component I want to pass another array. But for first component of rows I need to show date in picker view.
Please help me out.
You have to use two separate picker views, a UIDatePicker, and a UIPickerView. Read up on the documentation of the UIPickerViewDelegate and UIPickerViewDataSource to populate it with your array.

Appropriate way to add multiple UIPicker controls on page

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.

How to make my own UIPickerView?

Since UIPickerView can't be customized to the level I want (without taking a risk by hiding specific subviews), I need to roll my own to select a time.
I figure I can do this using two UITableViews, but I'm unsure of how to do 2 things:
1) How do I determine which cell is in the middle of the view (i.e. which one did the user select)?
2) How do I make the table snap to the cell nearest to the middle of the view once the user has stopped scrolling?
Thanks for your help.
Why do you say that UIPickerView can't be customized?. It has a bunch of delegate methods made to allow a lot of customization, such as view for rows, height for rows etc etc..
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html
Implement the delegate in your ViewController and customize it as you want.
You're just trying to select a time? Then use UIDatePicker. It is a picker view for time/date.
Depending on the type of customisation that you want, you might not need to make your own UIPickerView. You can return your own views for each component using UIPickerViewDelegate. Check pickerView:viewForRow:forComponent:reusingView:
The free Sensible TableView framework has a UITableView based date picker that you could use out of the box. Should save you a lot of time as it handles all the scrolling and table view resizing. Hope this helps.

Resources