I am using this code to push my next view controller, it was working fine with IOS 7, now I have changed the deployment target to 6.1. I am calling this code from tableview cell's didSelectRowAtIndexPath. Its causing a crash when the cell is tapped only the first time, afterward goes smooth. There is no crash log. It is still working fine on iOS 7.
UIViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"Test"];
[self.navigationController pushViewController:view animated:YES];
I tried setting "animated=NO" it works fine
[self.navigationController pushViewController:view animated:NO];
Where is the problem?
Also, I am setting cell's background color in cellForRowAtIndexPath, in iOS 7 shows the color but not in iOS 6.1
change:
UIViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"Test"];
[self.navigationController pushViewController:view animated:YES];
with:
UIViewController *view =(UIViewController *) [self.storyboard instantiateViewControllerWithIdentifier:#"Test"];
[self.navigationController pushViewController:view animated:YES];
Related
I just started checking AQGridView and new to iOS too in the source example ExpanderDemo the orientation is working fine for the first View but as i click any cell and next upcomming AQGridView does not effect View on GridView.
ExpandingGridViewController *controller = [[ExpandingGridViewController alloc] init];
controller.gridView.frame = self.gridView.frame;
[self.gridView setHidden:YES];
[self.view.superview addSubview: controller.gridView];
[controller expandCellsFromRect: expandFromRect ofView: cell];
[controller viewDidAppear: NO];
On the other hand if i present the view controller to second it works fine with the orientation but losses the Animation for Expansion; which i don't want to loose. What should i do?
ExpandingGridViewController *controller = [[ExpandingGridViewController alloc] init];
[self presentViewController:controller animated:NO completion:nil];
The last time I use AQGridView I got a lot of troubles, I suggest You should give a try to UICollectionView. Cheers!
I have this function in an IBAction button:
I start off with a table with a button, when that button is pressed this takes place:
TabBarController *v = [[TabBarController alloc]
initWithNibName:#"TabBarController" bundle:nil];
[self.navigationController pushViewController: v animated:YES];
[v release];
On the second view there is another button which when pressed does this:
NSArray *array = [self.navigationController viewControllers];
[self.navigationController
popToViewController:[array objectAtIndex:1] animated:YES];
This causes the app to crash, and at index 0 it does nothing. Is this because the second page is not a UITable like the first?
I want to be able to move from UITable view to UIView back and forth, should I use addSubview instead? I need the first view to have a navbar but the second shouldn't.
I think the problem is that [array objectAtIndex:1] is your current ViewController, so popping to the current view controller might be the reason of your crash (did not try it though)
So why don't you do:
[self.navigationController popViewControllerAnimated:YES];
simply add the following line in button code and it will work fine
[self.navigationController popViewControllerAnimated:YES];
In our iOS application with three UIViewControllers one after another, we would like to skip the middle one based on some condition and go directly from first to third. However, the user should be able to come back to the second one via the "Back" button on the third controller.
I tried [self performSegueWithIdentifier:#"segueId" sender:sender]; from viewDidLoad, viewWillAppear but this corrupts the navigation bar as indicated by the debug log. Calling this code from viewDidAppear works fine, but then the second view is already displayed, which is what I was trying to avoid in the first place.
I also tried [self.navigationController pushViewController:vc animated:NO]; but the result is similarly corrupted nav bar, even though this time debug log does not have such entries.
What would be the supported way of doing this (if it is at all possible)?
The target is iPhone4 with iOS 5.1, and the dev environment is Xcode 4.3.
I use the following code in an app. Works exactly as expected.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SecondViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
if (indexPath.row == 0) {
// skip second vc
ThirdViewController *thirdVC = [self.storyboard instantiateViewControllerWithIdentifier:#"ThirdViewControllerViewController"];
[self.navigationController pushViewController:secondVC animated:NO];
[self.navigationController pushViewController:thirdVC animated:YES];
}
else {
// push second vc
[self.navigationController pushViewController:secondVC animated:YES];
}
}
If you want to skip a view controller you can just call UINavigationController setViewControllers:animated: It will animate to the last controller in the supplied array, and the user will be able to "back" out of that stack.
You can build up the array of view controllers any way you like; perhaps starting with the existing array of view controllers:
NSMutableArray* newViewControllers = [[navController.viewcontrollers mutablecopy] autorelease];
[newViewControllers addObject: ...];
[navController setViewControllers: newViewControllers animated: YES];
navigated from one view to another will and when i pop my view back viewWillAppear method is not calling.
can you please let me know the reason.
When you load View the first time viewWillAppear method is called? try to use
[[self navigationController] popViewControllerAnimated:TRUE];
to return back
It's typical that these problems are caused by improper use of view controller containment. You need to look at your view controller hierarchy and research the following methods:
[UIViewController addChildViewController:];
[UIViewController removeFromParentViewController:];
[UIViewController transitionFromViewController:toViewController:duration:options:animations:completion:]
[UIViewController willMoveToParentViewController:]
[UIViewController didMoveToParentViewController:]
Read the Implementing a Container View Controller section of the UIViewController Class Reference.
If u are doing all well than ur application is crashed some where, use break point and check , even you can check and follow these steps......
step 1. for push in FirstViewController
SecondViewController *second = [[SecondViewController alloc]init]
[self.navigationController pushViewController:second animated:TRUE];
Step 2. for pop in SecondViewController
//check navigation controller exist in ur application stack
NSArray *arrView = [self.navigationController viewControllers];
NSLog(#"arrView %#",arrView);
for(int i = 0; i <[arrView count]-1, i++)
{
if([arrView objectAtIndex:i] isKindOfClass:[FirstViewController class])
{
[self.navigationController popViewControllerAnimated:TRUE];
}
}
I've also met this situation.
In iOS 5, it's ok.
But when I test in iOS 4.3.1, viewWillAppear is not calling.
So you need call viewWillAppear manually
You can try this
[[self.navigationController.viewControllers objectAtIndex:0] viewWillAppear:YES];
[self.navigationController popViewControllerAnimated:YES];
I have an iPad app that uses the storyboard board feature and then I have a separate .xib file for another view. I can switch to the separate view and its fine:
-(IBAction)SecondView:(id)sender{
SecondView *Second = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Second animated:NO];
}
But when I am in the Second View and try going back I do everything the same just with the first view controller, but It just goes to a black screen:
-(IBAction)FirstView:(id)sender{
FirstView *First = [[FirstView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:First animated:NO];
}
What do you guys think? Am I doing something wrong? What is the best way to switch views?
initWithNibName:bundle is for loading nib or xib files.
If you are loading from a storyboard, you need to use
FirstView *First= [self.storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER"];
IDENTIFIER is defined in your storyboard, it's in the Utilities, Attributes Inspector on the right side.
HOWEVER your real problem is that you shouldn't be loading from the storyboard at all. you should just be calling
[self dismissModalViewControllerAnimated:YES];
That call will clean up the presentModalViewController:animated: that you used to put the modal view controller up in the first place.
You presented SecondView using presentModalViewController:animated:, so you need to dismiss it using dismissModalViewControllerAnimated:.
- (IBAction)FirstView:(id)sender
{
[self dismissModalViewControllerAnimated:YES];
}