i have the following code
if ([[tableView cellForRowAtIndexPath: indexPath].textLabel.text isEqualToString: #"added"]) {
NSLog (#"hello");
FinalViewController *anotherViewController = [[FinalViewController alloc] initWithNibName:#"FinalViewController" bundle:nil];
NSLog (#"hello2");
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
NSLog (#"hello3");
and it does absolutely nothing on user click. when testing it, all logs appear so im not sure where the problem is located.
self.navigationController may be nil. How was the table view controller added to the navigation controller?
Have you checked if you have imported the header file on the top?
And why don't you try to use bundle:[NSBundle mainBundle] ?
Related
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];
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];
}
I have spent several hours on this, and tried various things. I can confirm that the didSelectRowAtIndexPath is indeed being run, and the specific object I am looking for is being returned.
The bit that isn't doing anything is the part where I am trying to display the SensDetailViewClass view. It runs the code, but the viewDidLoad method in SensDetailViewClass.m doesn't run, and the view doesn't change.
I would like to have the SensDetailViewClass displayed. I can confirm that the .xib file's owner is the SensDetailsViewClass.
Please help. Here's the code.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the selected item
Sens *info = [_sensInfos objectAtIndex:indexPath.row];
// initialise the detail view controller and display it
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"MainWindow" bundle:nil];
// set the title of the page
[details setTitle:info.heading];
details.selectedSens = info;
[self.navigationController pushViewController:details animated:YES];
[details release];
}
UPDATE: I got it to work by using this mechanism:
[self presentModalViewController:details animated:YES];
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"SensDetailViewClass" bundle:nil];
[self.navigationController pushViewController:details animated:YES];
i think you are fresher so nedd to check the link of tutorial
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
Are you sure your SensDetailViewClass class has MainWindow as its .xib file?
Please check it and replace nib name `
initWithNibName:#"MainWindow"
in above code
Thanks,
1 ) Are you sure y*ou have the navigation comptroller in the app* or its just the View Based application.
IF this is ok then ,
2)
// initialise the detail view controller and display it
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:#"You-Xib name for this View" bundle:nil];
// set the title of the page
[details setTitle:info.heading];
details.selectedSens = info;
[self.navigationController pushViewController:details animated:YES];
[details release];
I am having problems with getting a detail view to load using pushViewController. At first, I thought pushViewController was not working. BUT, then I tried using a different view controller and it worked. I can tell from tracing that the problem view controller is never loaded at all. In other words, I tried to eliminate the possibility that there was some error in the view controller by NSLoging in that object and I never see anything.
Does anyone have any ideas?
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
NSLog(#"hsitkjsdfkljlkd");
if (childController == nil)
childController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//NSUInteger row = [indexPath row];
[self.navigationController pushViewController:childController
animated:YES];
*/
/*
//modal = blocking
salesViewController *otherVC = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
//must set sale type
otherVC.strSaleType = #"Voice";
[self presentModalViewController: otherVC animated:YES];
//No close. By design, it is up to the otherVC to close itself
*/
//tipCalcViewController *detailViewController = [[tipCalcViewController alloc] initWithNibName:#"tipCalcView" bundle:nil];
salesViewController *detailViewController = [[salesViewController alloc] initWithNibName:#"salesView" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Just Check the
- (void)viewWillAppear:(BOOL)animated
{
}
of the salesViewController.
you are doing something wrong in this..
put the debugging point in the viewWillAppear and run it. you can get the error line..
just try it......Surely it will work for u...
salesViewController *detailViewController = [[salesViewController alloc] initWithNibName:#"salesViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Also make sure you are giving the IBOutlet connection to UIView.
In my case I had several IBOutlets that I removed from the Header file and forgot to remove the connection to these non-existing outlets in Interface Builder. So removing the obsolete outlets fixed the problem in my case.
When you're pushing from ViewController1 to ViewController2 then the code will be used like this so try this code,
ViewController2 *vw2=[[ViewController2 alloc]initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:vw2 animated:YES];
The Above code may be written on Click event of button or on didSelect delegate of UITableView
hello i am having same issue, i tried your solution but it didnt help me in my case..
i am not getting exception but view is not getting changed..
my piece of code is as below
printf("hi");
//Get the selected country
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
DetailViewController *aSecondView = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
// aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
[aSecondView release];
aSecondView = nil;
printf("bye..");
both hi and bye gets printed but view doesnt change..
i have wasted 2 days around it ..
plz help me out..
Check the nib name.How did you created the nib file for the detail view?.It will be created by default as DetailViewController in your case.So change the initWithNibName.Why do you set the aSecondView=nil?
as kovpas said , that subclass your controller from UIViewController instead of UINavigationController ,you use presentModalViewController. for implementing navigation controller put this code in your delegate class
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UINavigationController *nvcontrol =[[UINavigationController alloc] initWithRootViewController:viewController];
[window addSubview:nvcontrol.view];
[window makeKeyAndVisible];
}
Seems, that you subclass your controller from UIViewController instead of UINavigationController
Try to use
[self presentModalViewController:aSecondView animated:YES];
Dismiss it with
[self dismissModalViewControllerAnimated:YES];
in case if you un comment your commented code...one another problem that i found in your code... interchange these 2 lines...
aSecondView.selectedCountry = selectedCountry;
[self.navigationController pushViewController:aSecondView];
try Put it like this
[self.navigationController pushViewController:aSecondView];
aSecondView.selectedCountry = selectedCountry;
if you uncommnet the line it may create problem