I am using the StackScrollView iOS library in my iPad app. My master view initially consists of a table. When the user selects a cell, a View Controller is created and added to the stack as follows:
DualChartViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"DualChartPageVC"];
[vc setObj:newObj];
[((MasteriPadViewController *)[AppDelegate sharedDelegate].mainVC).stackScrollViewController addViewInSlider:vc invokeByController:self isStackStartView:FALSE];
This works as expected the first time a user selects a cell; however, the DualChart views are never removed, so in subsequent selections they simply pile up on top of each other (forcing the user to swipe each of them away multiple times).
How should I de-allocate these views properly so that there are never more than two subviews added to my StackScrollViewController (the table and the DualChartViewController)?
Any help would be greatly appreciated. Thanks so much!
Figured it out.
Although my StackViewController object was removing my view controller from it's viewControllersStack array, it for some reason wasn't removing it from slideViews' subviews. I modified my didSelectCell method so that if it wasn't the first selection made, I would remove the last object from slideViews' subviews before adding the new view. Now it works perfectly!
Related
Essentially I have a view controller where the user picks from three choices. Once the user chooses something, the view segues away to another view controller that displays some information regarding their choice for about 5 seconds and then segues back to original view controller automatically where the User must make more choices... (its basically a loop until something is accomplished).
The problem I am having is when the User touches their option, it seems to just segue back to itself without ever displaying the intermediary screen. I added a sleep(5); to the viewDidLoad but all that causes it to do is pause on the original choice screen for 5 seconds before segueing to itself. I also put in an NSLog in just to make sure it was actually using the new controller, which it is indeed.
I didn't include code since its so trivial. viewDidLoad on the new controller, has sleep(5) and the call to segue back to the original view controller.
I solved the problem by moving the code to viewDidAppear. Should have done that from the beginning honestly, just didn't think it through enough I guess.
I've set up a really simple project using storyboards including two views as shown here: http://i.stack.imgur.com/iRx21.png. The navigation can be done by either selecting a cell in the custom table view or hitting the back button labelled with "<<". Everything works fine except the following:
when I switch between the views, every time an instantiation happens. The profiling shows an increasing number of view objects. I would like to keep only one of each view and instantiation should be happen only once. What am I doing wrong? (I'm using ARC.)
Thanks in advance!
You should not link your back button to the parent view controller. This is what causes the new instantiation.
The way to go is to embed the table view into UINavigationController (in IB, choose Editor -> Imbed In -> Navigation Controller. Then change your segue to a Push segue. You can of course hide the navigation bar etc. to make things look exactly as you like. Then, link the back button to the controller with an IBAction and in the handler do a simple
[self.navigationController popViewControllerAnimated:YES];
This would be the appropriate logic of what you are doing. Of course, you can also push the web view modally and then handle the button click with
[self dismissModalViewControllerAnimated:YES];
I am writing an app that pulls information from a database, displays in a table, and allows the user to get details by selecting an item from the table. Whenever the table updates, the values in the list are correct, but the table displays the old information (i.e. if the table originally had 3 items and now has 2, the table will display the original 3 items, but break if the user tries to tap the 3rd item). The same issue occurs with my details view. If the user selects one value, the view changes for that information. If they navigate back and select a new value, the view changes but displays the information from the first selection. I've attributed both of these to the views not calling viewDidAppear when they appear. I am using a Navigation Controller to load the views, but they still aren't calling the method.
This is how I show my listView : UITableViewController
-(IBAction)viewInventoryClicked:(id)sender {
[DBHelper getAllBottles:[appDelegate getDBPath]];
if(self.viewList == nil) {
//instantiate view
}
[appDelegate.navigationController viewWillDisappear:YES];
[appDelegate.navigationController pushViewController.self.viewList animated:YES];
}
My detailsView (UIViewController) is shown in a similar fashion. The navigation controller resides in the AppDelegate. The main window is loaded with:
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
The mainWindow and my ModalView are both successfully calling the viewDidAppear methods. I am completely stumped on why these other two are not calling them. Thanks in advance for the help.
I figured it out. The issue wasn't in the way I was changing view, but in the way my interfaces were set up. I had all of my viewControllers in my MainWindow.xib, instead of the in the *.xib of the view previous.
I am attempting to make an iPad app. I started out using the splitViewController app template, and realized that was a bit restrictive, so I've started moving everything over to a regular View-based app template. However, I'd still like to have a table on the left with a different view on the right. I have a NIB with a tableView on the left and a view on the right. The tableView is still in a separate class. Is there a way to load that view into the tableView of the NIB?
I'm trying code that looks like this:
rootViewController = [rootViewController initWithShow:assetOneID];
[rootViewController.tableView reloadData];
[htmlPage viewDidLoad];
htmlPage.myContent = rootViewController.tableView;
[htmlPage.myContent reloadData];
htmlPage is the main page with the table and the other view. myContent is its table. rootViewController is the class that I used for the table of items. When I try to run this(and I know there are items in rootViewController's table through using NSLog), nothing happens. The table just stays blank, even though it should have the title of the item in rootViewController.
I'm probably missing something obvious here, but I've tried many different things and none of them have worked.
Thanks in advance for any help.
Delegation sounds like a solution but, regarding the blank tableview - Have you set the delegate and data source for the tablview in IB or programmatically?
I'm writing a program with a UITableView with and add button in the Navigation Bar which leads to an edit page. When you click on an item in the table, a view (rView) is pushed with information pertaining to that item. This view has an edit button that also leads to the edit page. Is there a way that I could put an if statement for the done button on the edit page that says "if parentViewController is the UITableView to go to rView, else popViewController?" I would assume there is a way to do this, but I'm not sure of the syntax to do so. Thanks
If I understand correctly you have a UINavigationController and push onto it
a UITableView
an "rViewController" (you can't push a view, must be a controller)
an "EditController"
But there is a possibility that step 2 is omitted and you go directly to the edit screen.
Now when the last controller is popped, you want to be able to always go to a "rViewController", even if it's not on the stack.
First of all, the parentViewController is NOT the previous controller on the stack, but rather the UINavigationController itself, so it has nothing to do with the present problem.
The way to do this is by setting the UINavigationController's viewControllers property explicitly with an NSArray. I haven't tried this but this should work:
When a user presses the "add" button, instead of just pushing the edit view controller, do something like:
NSArray* stack = navigationController.viewControllers;
navigationController.viewControllers = [stack arrayByAddingObject:rViewController];
[navigationController pushViewController:editController animated:YES];
(By the way, I would suggest not using names like "rView" except maybe for very short-lived local variables, like in a loop. Using descriptive names is very much part of the Cocoa idiom and will help you a lot in the long run.)