I have a UINavigationController. In its toolbar is a segmented control with two buttons. Each button relates to its own UITableViewController.
What I'm trying to achieve is someway of wiring up the navigation controller so that the views are switched depending on which button within the segmented control is active.
I assume I should hold on to the table controllers, because I want to preserve the scrolling position within each view, e.g., if the user was positioned at the top of table 1, and the bottom of table 2, then this information should be preserved when switching.
Any suggestions would be gratefully received!
Would it be possible to just switch the dataSource instead of having to deal with two separate table views? Preserving the scrolling position can still just as easily be done, and you end up using less memory (one table view and two data sources instead of two table views and two data sources).
With only 128MB to spare, memory efficiency is king on the iPhone.
Joel's suggestion is a good one. Another possibility is to use two different UITableViews in your view controller, and swap them out manually. There's nothing special about a UITableViewController; it's just a UIViewController with its tableView setup for you. Use a standard UIViewController, add two outlets for tables, hide one, and swap them when your UISegmentedControl is toggled.
I've used Joel's method. Very efficient.
Use the segmented control to call a method that sets a sets a variable, then sends [tableView reloadData].
Then the tableView: numberOfRowsInSection: and tableView: cellForRowAtIndexPath: retrieve their data depending on the value of the variable set by your segmented control's method.
Related
I want to use the same TableView for 3 of my tabs instead of using 3 identical TableViews. I created three navigation controllers (one for each of the tabs) and linked them to the same Table View Controller But if I run the app with the storyboard like the picture below, it works for the first one of the sharing tabs, but for the other two I get a black screen where the tableView should be. So I want to know if it is even possible to make it work with this setup?
I'm trying this, so I don't have to make a litte change in the tableview 3 times.. The 3 tabs are populated with the same data too, just filtered differently, so just filter the array depending on which parent navigation controller would be simple I suppose.. But I need to know if this is a possible way of sharing view or not.
I would suggest a different approach. Just have three different table views. But since the question is not about being the right approach, I would say that the best way to do it is to do it by code, removing the tableview from the super view (The view controller's view) and moving it to a new view controller when the delegate from the tabbarcontroller is called. Keep in mind that you will also have to assign the delegate and datasource for each view controller.
What I need may be pretty basic, but I'm definitely not sure as to how to proceed (I've done that before but none of my choices seem that Cocoa-friendly).
Ok, let's say we've got 2 NSViews - one next to the other:
The one on the left serves as a menu.
The one on the right will show a NSView (from a different XIB perhaps?) depending on the selection on the menu.
My questions :
How should I go about loading the different NSViews into the rightmost NSView?
How do I make sure that the subview (the one currently active) is properly resized when the window is resized?
rdelmar's solution should work, but another approach, which may be simpler, is to use an NSTabView to handle switching between the content views. You can hide NSTabView's tabs using the settings pane in interface builder, or by calling [self.tabView setTabViewType:NSNoTabsNoBorder]. I'd probably use a table view for the left side. When the user selects a row, you do something like:
-(void)tableViewSelectionDidChange:(NSNotification *)notification
{
[self.tabView selectTabViewItemAtIndex:[self.menuTableView selectedRow]];
}
The NSTabView can/will take care of properly resizing its content views as long as you've set up its and its content views' autoresizing masks (springs and struts) properly.
You should be able to create a custom view in IB that looks like your yellow view, and set its resizing behavior to expand in both directions with window resizing. Then, when you get your new view (by just referencing one you already have or loading a new xib), add it as a subview of the custom view, and set its frame to that of the custom view. I think that views resize their subviews by default, so it should resize correctly with the custom view.
I have a grouped UITableView in class A and if you select a row in section 0, I want it to open up to another UITableView. In the first view, I have a lot of other methods and buttons and custom designed stuff, so I don't want to create another XIB for the other table view since I'll have to copy over all the methods and custom designed stuff. I was thinking creating another XIB, but subclassing the class under the original class A this way I can use the methods of class A without having to redefine them again in the new class. But I'm having problems with this. Is there a better way? Can I have two table views in one XIB, and just hide one till the other is called up? But that seems a little messy..
If you simply try subclassing the existing viewcontroller it will have the same info for the selected row, hence it would have to grow exponentially in order to make display the right UITableView.
If your concern is redefining methods, then simply create a class that will hold those particular methods and include it in the UITableViewControllers that will be using them, that way you will only define it once. This way you can simply create a new UITableViewController and push it into a navigation controller everytime you select a given cell.
As an alternative of showing all options within one UITableView you can try the following: you can probably try adding a UIScrollView inside the UITableViewCell. I would make it scroll horizontally while keeping the UITableView scroll vertically.
Currently, I have an NSStatusItem that, when clicked, shows a custom view below it. The view contains some information and text fields. What I need is for a separate custom view to merge with the first and appear below it, as in further down the screen, not on top or behind the original view. This needs to be a separate view because there are actually several custom view that will be appended depending on what the user does in the first view. I would like to be able to independently add or remove each of these without affecting the others. I've dug through apple documentation but I haven't found anything about putting one custom view inside another programatically.
NSView has an addSubview:positioned:relativeTo: method you can use to add and order views to appear above or below each other. Use superview: to access this method on a container from any of its subviews.
Edit:
Try adding both views to an NSSplitView with a hidden divider. To hide the divider, subclass NSSplitView and override the dividerThickness: method to return 0;
I am aware how to use the above to transition between two UIViews - but if I have a table in a UIView, and I want to replace it with another Table, can I transition just the two tables, without having to transition the entire view?
Yes you can transition between the two views. Or, you can make your transition and while doing so bring the second Table to the front by using [self bringSubviewToFront:(tableView)]; Then when you want to transition back, just bring the first tableView to the front.
I don't see why not. Have you tried it yet?
UITableView inherits from UIScrollView and UIView, so you will be able to use CoreAnimation on it.