Adding UIPickerView and UIDatePickerView - in a UITableViewController - ios

I have a UITableViewController where I want to display a date picker when a row is selected and a pickerview when another row is selected (I plan to hide the other when one is displayed).
I am having trouble adding the datepicker and picker view in the story board. I can add one and make it work fine. But I can't drag the second one in the view. (I was able to add on top of the table view but I don't want that.)
To go around the problem, I thought I will add the other picker programmatically and assign the same frame, but that doesn't work either.
Any suggestions on what may be preventing me from adding a datepicker and picker view to a UITableviewcontroller?

I think you should use UViewController and add UITableView, UIPickerView and UIDatePickerView

Related

UITableView inside a UITableView?

Generally:
Is it OK to add a UITableView as a subview of another UITableView? Or, should I create a UIView and add each UITableView to it?
Specifically:
For a ComposeTableViewController with a typeahead, like in the iPhone's native Mail app, which approach would you recommend and why?
Note: I prefer to construct things 100% programmatically (no Interface Builder).
Subclass UITableViewController.
Then, to show the typeahead results, create and add a resultsTableView as a subview of self.tableView positioned directly underneath the the cell (of self.tableView) with the typeahead text field.
The nice thing about this approach is that resultsTableView scrolls with self.tableView automatically.
But, is it OK to add a UITableView as a subview of another UITableView?
Subclass UIViewController.
Create and add tableView (custom property) as a subview of self.view.
Create and add resultsTableView also as a subview of self.view.
The annoying thing about this approach is that I have to reposition resultsTableView manually anytime self.tableView scrolls.
I think I'd prefer approach 1, but adding a UITableView as a subview of another UITableView just seems smelly to me.
TableViews cannot have subviews. You can try adding a tableview as the view of a TableViewCell, but then you have to ask yourself how it would scroll, if you tried scrolling in the subtableview would it scroll the child tableview or the parent tableview? It is much easier to present multiple tableviews within a view. This can be done easily by setting your custom viewcontroller as the datasource of both tableviews contained within its view and then comparing the tableview pointer that is sent as a parameter of the datasource method to the two tableview pointers that are IVars of your custom view controller.
Hold stuff like this in a container. Create a container view controller which only does typeahead. This container view controller will hold your main table view controller (and its table view) and it will hold the typeahead view controller (and its view).
It will keep the logic needed for the typeahead out of your main table view and as a bonus you might end up with a reusable typeahead container which could be applied to other views.
Yes it is good to go for adding UITableView in as a cell of another UITableView.
I had one issue and posted a question
Multiple Views as subviews
And requirement was like a group of controls with list of other controls. I thought that time that it will be messy if i'm going to add UITableView as a cell of UITableView.
What i found that... Boy !! it's how iOS meant to be. There is no any lag while doing this.
Tested for below functionalities:
Scrolls like a charm
Separate delegates called for each
Reordering of both UITableView cell
Swipe and remove cell
Runtime datasource update for both UITableView and reload both at the same time.
There is no any reason not to add subview UITableView.
You can do it but it is against the principle of MVC. You will be setting the delegate of a view to another view which is wrong.

iOS picker view as default input method

I have labelA in my custom tableview cell. When I click on the label I want picker view to be shown in the bottom of the screen in order to choose available options.
My question is: Do I actually need drag and drop PickerView into my view in storyboard or I can just invoke it as default input method? (Same as keyboard for text field)
If yes, how do I do that? - All I want when label is clicked show picker and hide it on when selection is finished. Could you please provide me some examples?
I am developing under swift but iOS example is fine as well.
Thanks for any help!
Edit:
Well label is not principle, I can use just input trigger from the cell directly. Idea after click show picker view and hide it after selection.
What I mostly do is use a UITextField and set the inputAccessoryView property to an instance of UIPickerView. This will display the UIPickerView once you tap on the UITextField instead of the default keyboard.
You can instantiate the UIPickerView all in code in your tableView:didSelectRowAtIndexPath method. You can either add it to your view controller using self.view addSubView. You will have to write code to place it properly on the screen with your table view. You might want to resize your table view so it shrinks and your picker view is shown on the bottom of your view.
An easier way could be to show a modal dialog with your UIPickerView already set up.
UPDATE
Create an new controller that is of type UIViewController.
Drag a UIViewController onto your storyboard and give it the type of the above controller and a storyboard id. I use the name of the UIViewController created.
Add your picker view to that and configure your data source.
Create a delegate for the option selected and have it return the item selected.
- (void)selectionMade:(NSString *)selectedValue;
In your table view controller, implement that delegate method above.
In tableView:didSelectRowAtIndexPath, load that view controller and show it.
[self.storyboard instantiateViewControllerWithIdentifier:#""]
Your delegate method will get that value and you can retrieve the cell using tableView.indexPathForSelectedRow.
Update you cell accordingly.

Static TableViewCells Hidden Above Screen

I had three UIPickerViews in a Static TableView that was working well and decided to delete top most UIPickerView. Now the UIPickerView that at the top of the view is hidden. If I swipe my TableView down, I can see it but cannot select it.
I believe my TableViewController is set up correctly but may be missing something. I tried deleting the TableViewController completely in StoryBoard but this did not correct it.
Has anyone encountered a problem like this? I can post code if necessary.
Thanks!

Floating button over UItableview using storyboards

I have made a table view using prototype cells on tableviewcontroller from storyboards.
I want a floating button over that uitableview. (button won't scroll with the tableview).
While searching for a solution..I found out that it is possible by adding button to the superview (in that case Uiviewcontroller subclasses Uitableview).
Can any one tell me how to do that using storyboards??
I think best thing you have to do is to create a UIViewController and add it a UITableView. Then you can add also the UIButton you want to the view controller's view. Don't forget to set the view controller to be the delegate and data source for your table view, and to add <UITableViewDataSource,UITableViewDelegate> to your view controller interface.
If you must do it using Storyboards and not in code, then you need to use a UIViewController and not a UITableViewController.
Add the UITableView and make it full screen - link up its Delegate and DataSource to the UIViewController and adhere to the two protocols in the .h file of your UIViewController.
When adding the button, drag it into the view hierarchy in the "Document Outline" sidebar, and not by dragging it onto the UITableView. Be careful if you're ever dragging the button around the view because if you drag and drop it on top of the UITableView then it will become a subview of the UITableView. If you want to move it around you'll need to select it and then use the arrow keys.
Anyway, apart from that it should all be very easy - add your constraints to keep it in the right place and you should be able to use the button as normal.

UITableViewController does not automatically resizes and repositions its table view when there is in-line editing of text fields

UPDATE (SOLVED ALREADY) :)
I tried to recreate my scene from scratch. And I found out that if the Class of the table view controller is "UITableViewController", the repositioning of view when keyboard appears happens properly. But when I set the Class of the table view controller to my custom class, the repositioning doesn't happen. Why is this so? Given that my custom class is a subclass of UITableViewController and nowhere in my implementation did I implement any data source and data delegate since I am using static cells?
I forgot to add the delegate in my interface declaration. Now it's working already.
#interface CustomClass : UITableViewController <UITableViewDelegate>
I have a UITableViewController where the tableview content is static cells and style is plain. I added 7 table view cells. In each cell, I added a text field.
When I click on a table view cell, the keyboard shows but the table view did not reposition; thus hiding the table view cell that I selected.
I have solved this before but I was using a view controller then which I embedded inside a scrollview. But seeing from documentation, UITableViewController, which has a scrollview by default, is supposed to automatically resize and reposition it's table view.
I am working on XCode 5 and using iOS 7 latest version.
You can change the offset (y) of the tableView whenever textField's action is didBeginEditing.
If you need any more help let me know ;D
It should automatically change its size, but not necessarily adjust its position/offset.
Are you sure the table view still covers the entire screen, even below the keyboard?
You can check this by scrolling and looking at the scrollbars.
If you want to adjust the content offset, do so in the callback when the user begins editing the text field.
Eliminate the code that sets the content offset of the table view.
The table cell for text field with the first responder status should automatically scroll above the keyboard. You shouldn't have to write a lick of code for this.
If you are using static cells, make sure that your table view controller does not implement the table view data source methods. Also, the view controller that you dragged onto the IB canvas must be a UITableViewController; it can't be a UIViewController that contains a UITableView dragged from the objects library.
After thorough checking, I realised, my custom class only subclass UITableViewController without adding the delegate :(
below solves the problem... at last! :)
#interface CustomClass : UITableViewController <UITableViewDelegate>

Resources