iOS picker view as default input method - ios

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.

Related

Change detailview according to masterview in UISplitViewController

I have a UISplitViewController which has a searchfiled in the first row of its master view which is a tableview as we all know.
And my detail view contains a collectionview. I have to update my collectionviewcells according to the seacrhfield text. So how i update collectionview cells just when editing begins in searchfield.
I want to show a activityindicator too when user started searching.
So basically i want to control DetailViewVontroller's properties from MasterViewController's class whenever i want. Is it possible?
You can use
[self.view addSubview:lbl]
to add the label to your tableview controller's view.
If you want to replace the view controller,
take a look at the showDetailViewController:sender: method in this:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UISplitViewController_class/index.html

Adding UIPickerView and UIDatePickerView - in a UITableViewController

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

Implementing A Mail app-like User Interface

I am trying to implement a user interface that is similar to the iPhone's Mail app.
The main screen displays a table. From the table the user can select a cell, at which point the next screen is launched. At the bottom, there is a bar showing a short text and an icon.
The second screen displays the details of the cell. It will also be a table display. The bottom bar shows icons associated to this screen.
What kind of layouts do I use to implement this in Xcode?
1. Do I use a View controller, add a View and embed a TableView and a Toolbar inside that view?
2. Do I use a Table View Controller and add a Table View inside it and use the bottom tool bar that comes with the table view?
In the Table View Programming Guide for iOS, under 'Recommendations for Creating and Configuring Table Views,' it says 'Use an instance of a subclass of UITableViewController to create and manage a table view.' When I use this, the bottom bar can only be fixed or disappear when going back and forth between two screens via segue. That makes me wonder whether I should just use a View controller which is against the recommendation.
Use a UIViewController
Why?
If you are going to display more than a tableView then it is recommended to use a UIViewController for the storyboard.
UIViewController are much more flexible. I guess your confusion comes from the following documentation line:
Use an instance of a subclass of UITableViewController to create and
manage a table view
This does not mean you must to drag and drop a UITableViewController on the storyboard. It means your class need to inherit from UITableViewController or at least implement the deleguate and datasource methods.
You would use UITableViewController only and only if you need to display a tableView.

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>

iOS: How to change a label with a next and a back button (DetailView)

I've got a Master-Detail Application and in my DetailView I have got a "back" and "next" button.
How the buttons should work:
If I click on the back/next button, the label (which comes from a TableView with SearchBar from the MasterView) should change to the previous/next entry of the TableView.
My problem is that I don't know how I can do that.
I searched in this forum and found this topic iOS: Button to access next Tableview cell, but I don't understand it (I am new in developing for iOS).
Can you help me please?
EDIT:
It is an iPhone App, with Storyboard and segue from MasterView to DetailView.
And it is a dynamic TableView.
The basic process is to make the class that can provide the data be a delegate of the one that needs it.
Create a new protocol.
Make the master controller implement the protocol.
Give the detail controller a property that refers to an object of
that protocol.
In prepareForSeque:, set the detail's delegate to the master
controller.
When the buttons are tapped, call your delegate for new data.

Resources