How do I access the UITableView in the XCode "Navigation Based Application" - iphone

This "wizard" gives me a tableview to work with when I build and run. RootViewController is subclassing UITableViewController. Opening up the XIB, there is a table view, but what is the name of the tableview instance being displayed?
I'm trying to reload the tableview after a receiving data from an asynchronous URL request and I don't know what object to call "reload" on.

The UITableViewController class has a property tableView to access the UITableView it's using.
So you can do that inside the RootViewController class:
[self.tableView reload];

Related

Calling addSubview after removeFromSuperview

I am working on a simple UI, but am running into trouble with addSubview calls made after a removeFromSuperview.
In my viewController I have an IBOutlet UITableView
#property (strong, nonatomic) IBOutlet UITableView *tableView;
Depending on the state of the data, I remove the tableview from my viewControllers view.
[self.tableView removeFromSuperview];
So far so good, the view is removed. When using the debugger, I can still see that my viewController has a valid handle to the tableview. The problem starts on the next line when I call addSubview.
[self.view addSubview:self.tableView];
[self.tableView setDataSource:studyResult];
[self.tableView reloadData];
It seems to do nothing and I can't see any change in the UI. I have tried to set the frame on the tableView and still no results.
Have any of you seen this behavior?
Joe
Hi Joe can you give me more code for see what are you going? what I get, is that you have your control and a tableview view inside that you want to shot just when you have your array with the data? if is like that why you don't set Hide the tableview when you haven't the data? every time that you refresh the data for the table you have also to use the method reloadData for refresh the table
Depending on the state of the data, I remove the tableview from my viewControllers view.
Consider segueing to another view controller with a table view instead of swapping out table views in a single view controller. Or, if the new data is a subset of the old data, then leave the table view in place and filter its data.

interact the navigation controller bar button with embed container view

I've created a UIViewController, and insert a container view in it, which embed a UITableViewController. As the image described above.
When user click the Table View Cell, I'd like to add a UIBarButton on the Navigation bar.
But, how can I manage this? I can rise the DatePicker when click on Table View Cell, but when I call self.presentingViewController in table view controller implementation file, it returns (null), same as when I call self.parentViewController
You're probably trying to access the parent controller too early. If you log self.parentViewController in viewDidLoad, it will return null, but it should return the correct controller from viewDidAppear, and certainly from the didSelectRowAtIndexPath method. Using parentViewController in this context is correct, not presentingViewController.
I'd suggest to implement the UITableViewController Delegates and Datasource Methods in the ViewController itself.
That way you don't have to worry about accessing the ViewController containing the UITableView.

iPhone: how to create two controller in one NIB file?

I'm a little bit lost. I have created a small app that is starting with a tab bar and in one of its view there's a button that should open a Navigation view that contains a table view.
In my NIB file I have put a Navigation Controller that contains a TableView Controller. I have created a sub-class called MyTableViewController which inherits from the UITableViewController. In the NIB I have configured the Custom Class of the TableViewController with my subclass MyTableViewController.
When the button of my App is tapped, I'm loading the NIB file with the initWithNibName but it returns me a UINavigationController.
How does it work to request the creation of MyTableViewController and get a pointer on it when I'm loading my NIB?
Thanks,
Sébastien.
This one has caught me out a few times.
When you do initWithNibName it will take the class from the custom class of the File's Owner, not the custom view of any objects .
I dont actually bother subclassing from UITableviewController any more. Just create a view controller and drag in a table view as a subview. Just make sure you hook up the data source and the delegate.
Link your TableViewController to an IBOutlet so you don't have to mess with initWithNibName.

iPhone - placing tableview within a view in another nib. Window-based

I created a window based application, and I created a separate UITableViewController file called "HomeViewController" which right now only has a basic table.
In the MainWindow.xib file, I put a UIView in the bottom half of the screen, and I wish to put the HomeViewController tableview within this newly added UIView called "conferences".
Any suggestions as to how to push this file?
First off, usually your primary first view originates from a view controller that is loaded by the UIApplication object. The MainWindow nib's owner is UIApplication so you probably don't want to be mucking with the MainWindow nib. Rather, you want to muck with the view of the view controller loaded by MainWindow nib. If you look at the view displayed in IB for MainWindow.nib, it should say which view controller's view it is loading.
So, in IB for the view of view controller being loaded by MainWindow nib, this is where you want to place your UITableView. For purposes of this explanation, I will call this view controller, MucksViewController and associated nib, MucksView.nib.
I think what I would do, then, is drag and drop a UITableView into the view for MucksView.nib. Position it in the bottom half of the screen, as you described. Attach this UITableView to an IBOutlet property in MucksViewController header file. Next, drag and drop a UIViewController object into the main window for MucksView.nib. Make this UIViewController object's owner your HomeViewController class and also attach it to an IBOutlet property of type HomeViewController in MucksViewController's header file.
Now, in MucksViewController's class file, probably in viewDidLoad method, programmatically make the HomeViewController object the data source and delegate of the UITableView object.
But, I'm wondering, do you really need HomeViewController? It would be cleaner just to make MucksViewController the data source and delegate.
I hope this helps and is not too confusing.
Instead of a UITableViewController, use a UIViewController which implements the tableview delegate and datasource. in your MainWindow.xib, add a standard uitableview as a subview to the view where it should be. then also drag a HomeViewController to the xib (which should now be a uiviewcontroller sub class). click on the tableview, open the inspecor, go to connections, and drag the delegate and datasource to the HomeViewController in the xib.

How do I reload a tableView contained within a UIViewController?

I want to reload the data within a table view that is contained on the root view of my application.
The root view of my application (called RootViewController) is a UIViewController that has a corresponding NIB file. I added a UITableView component to the RootViewController.xib via IB. In the header file RootViewController.h I ensure RootViewController conforms to . I have all this linked up correctly in IB and all the appropriate methods get called, viewWillAppear etc.
My question is, how can I get access to the UITableView so that I can call reloadData on it?
The following code won't work because 'self' is a UIViewController, not a UITableViewController.
[[self tableView] reloadData];
If I use the above code I get the following warning and my application crashes on startup:
'RootViewController' may not respond to '-tableView'
You need to add an IBOutlet to your controller and link the that outlet to the tableview within Interface Builder. The NIB loading process will reconnect these outlets, giving your controller a reference to the table view.