how to push UIViewController from UITableView - ios

So basically, how can I push a UIViewController from a UITableView.
I have an array of contents on the TableView I need to tap inside the content and get the ViewController as result.
I tried making a - (IBAction)PushViewController:(id)sender but I can't reference the TableView.
Yes, i'm noob... ):

If you set a UITableViewDelegate for your table view, tableView:didSelectRowAtIndexPath: will get called when someone taps on a cell. At that point you can push another controller, optionally telling it what to display.

Related

set size of tableview in ios storyboard

I want my ViewController to be shared by a tableView and a TextView, where the TextView would appear beneath the TableView. But the TableView insists on taking over the entire scene/screen. How do I set the height of the TableView in the storyboard so I can make room for my TextView? (Please notice that I am not asking for a footer, which is actually what I am trying to change from)
The problem is that you are using a UITableViewController, which means that you get a scene with a full-screen UITableView.
To avoid this, use a normal UIViewController scene and just insert the UITableView into the interface manually (and configure its delegate and dataSource to point to the view controller).
UITableViewController is just a convenience. It doesn't do anything for you that you can't do yourself with a normal UIViewController. And in your situation, it is an inconvenience instead of a convenience.
Add a container view to your ViewController and link to an "external" UITableView instead of the provided UIView that comes with it when your drop it into your storyboard.
Send data via the segue, get it back via a delegate.
This way you can freely design your View with very little headaches.

Custom UITableViewCell Button selected - reload data

Alright let's say I have two ViewController, FirstViewController that contains a table and the CustomCell. I set up the action of the button in the CustomCell and it does what it is supposed to do but I want to call the [tableView reloadData] function in my FirstViewController.
What is the proper way of calling this function after the button is selected? Is there a way to set up something in FirstViewController that gets called when the Button in the other Class is selected?
You're best bet, if I understand your question correctly, is to use the Delegate Protocol in the second view, which returns a message to the first view controller.
See my answer here on how to setup a delegate:
How to declare events and delegates in Objective-C?

Trigger Change on UIViewController from UITableView(WEPopover)

I have a UIViewController and I am using the WEPopover controls to generate a drop-down on the view controller. The content for the WEPopover is held in a UITableViewController. The WEPopover is triggered when a UIImageView is pressed on the main UIViewController
WEPopover GitHub Link
I am aware that once a row in the table is selected the didSelectRowAtIndexPath triggers. Where I am facing a challenge is taking the result of the selected row, and then triggering a change on the main UIViewController.
What I am attempting to do is take the string in the row I have selected in the UITablewViewController, and then apply that string value (Hex String, using UIColor Extended from GitHub to convert to UIColor)as the new color overlay of the UIImageView which is located on the UIViewController
Simply you can define a delegate protocol for your UITableViewController, and a method, such as - (void) tableViewControllerDidChooseValue:(id)sender.
Make the main view controller conform to that protocol. Upon showing the UITableViewController, add the main view controller as the delegate for the UITableViewController.
Once didSelectRowAtIndexPath is called, call the delegate (main view controller)'s method with the updated value.
You may use this as a chance to dismiss the UITableViewController.

How to use a TableView inside a UIViewController?

I want to add a simple static TableView to my UIView. So i dragged it into my UIView. Added the TableViewDataSource and Delegate Protocols to my ViewController class. Created an outlet to my tableview and connected the datasource and delegate outlets to the viewcontroller.
But i still get an error message which says that Static table views are only valid when embedded in UITableViewCOntroller Instances ? Any Ideas how to solve this Problem ?
PS: I am using UIStoryboards for designing the UI
Use a containerView (drag one onto your UIView) which will link to a UITableViewController instead. You will use the prepareForSegue method to initialize the table view controller.
Oh, and you might want to accept answers that help you or no one will help you anymore.
If you want static cells, in your Storyboard, click on the tableview, then in the inspector, change the Content from 'Dynamic Prototypes' to Static Cells. You can also segue these cells to a new controller without having to set up data sources and delegates for the table.

How to make a callback from a UITableViewController to another UIViewController

I followed this discussion: UITableView issue when using separate delegate/dataSource, and even though I found it super informative and useful, I have a follow up question:
So I've got a similar setup where I have a UITableView within the UIView. The UIView is controlled by it's own UIViewController (let's call it MyUIViewController) and also I moved the delegate and datasource for the UITableView into a separate subclass of UITableViewController (say, MyUITableViewController).
Everything works fine with the tableView.
The question is, how do I make a callback from MyUITableViewController to the MyUIViewController? For example, if the user selects a cell under the tableView which triggers didSelectRowAtIndexPath, I need to update something on the UIView which is actually a parent of this UITableView. So I basically need to send a message to MyUITableViewController. How would I do that?
You can use a delegate pattern in this case. I have a similar answer with sample code in this SO . In your case, the parent view controller is MyUIViewController. And the child view controller is MyUITableViewController.

Resources