iPhone SDK: pushViewController crashing - iphone

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

Related

PushViewController does not work when called from App Delegate

I have a tab-bar based app. When the app becomes active, I want it to go to the second tab bar (SecondViewController) and then, open DetailViewController.
Here's how I'm doing it:
AppDelegate.m
- (void)applicationDidBecomeActive:(UIApplication *)application {
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
SecondViewController *secondView = [[SecondViewController alloc] init];
[secondView openDetailView];
[secondView release];
}
SecondViewController.m
-(void)openDetailView{
NSLog(#"open detail view");
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
[[self navigationController] pushViewController:detailViewController animated:YES];
}
openDetailView() does run (as I see the nslog working), but the DetailView does not get pushed? I know the code works because I have identical code in an IBAction which DOES push the detailView. The problem has something to do with it being called from the AppDelegate (or switching tabs).
So why doesn't the view get pushed when I call it from the App Delegate? Any help is greatly appreciated.
You push detailViewController to the Navigation-Stack of secondView, but secondView is in nowhere.
Try this...
SecondViewController *secondView ...
[self.tabBarController pushViewController:secondView animated:YES]; <==
[secondView openDetailView];

pushviewcontroller not working because self.navigationController is null

I have a big problem: on method didSelectRowAtIndexPath I always get null to self.navigationController. I have a UIViewController that contains a UIsegmentedControl and a subView. On this subView I add the controllers for each segment selected. For each segment a have a tableview. Here is the problem: when I select a row from this tableview I can't do push for next controller because self.navigationController is null.
Please help me..Here is my code : http://pastebin.com/qq0vf7mq
without the code :
navigationTelephone=[[UINavigationController alloc] init];
[self.view addSubview:self.navigationTelephone.view];
[self.navigationTelephone setNavigationBarHidden:YES];
[self.view addSubview:tableViewTelephone];
I think You have initialize the UINavigationController like below
[[UINavigationController alloc] initWithRootViewController:ViewControllerOBj]
Updated:
You initialize an instance variable navigationTelephone and display it, but you use self.navigationController to push!
Use [navigationTelephone push...] instead
Try this one:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
myAudiPhoneInputViewController *myViewController = [[myAudiPhoneViewController alloc] initWithNibName:#"NIB NAME HERE" bundile:nil];
self.myaudiPhoneInputViewController = myViewController;
[myViewController release];
[tableViewTelephone deselectRowAtIndexPath:indexPath animated:NO];
if(indexPath.row==0){
NSLog(#"Tel.personnel... %#",self.navigationTelephone);
[self.navigationController pushViewController:self.myaudiPhoneInputViewController animated:YES];
}
}
You haven't instantiate your myaudiPhoneViewController that is why it's not pushing the view.
Just check by changing,
self.navigationTelephone=[[UINavigationController alloc] init];
Naveen Shan

New view is not being loaded - am using pushViewController

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];

Pushing UIViewController onto a UINavigationController

The other day I asked about using a UINavigationController as a child of a UIViewController. I got that working via the answer. Now what I'm trying to do is push a controller onto the nav stack. When a table cell is touched, I do the following:
- (void) showSetup {
NSLog(#"Showing Setup");
SetupViewController *controller = [[SetupViewController alloc]initWithNibName:#"SetupViewController" bundle:nil];
self.setupViewController = controller;
self.setupViewController.title = #"Setup";
[self.navigationController pushViewController:self.setupViewController animated:YES];
[controller release];
}
I can see the log statement in my console, but the view never changes. Am I missing something?
Hmmm, well it's a bit tricky without knowing the details of your implementation -- I assumed that you implemented your navigation controller as in the linked article. Also although you give no details it sounds like you've added a table view controller somewhere along the line, so I made the UIViewController conform to the UITableView protocols to handle everything in one place:
#interface SOViewController : UIViewController<UITableViewDelegate,UITableViewDataSource > {
UINavigationController* navController;
}
- (IBAction) pushMe:(id)sender;
#end
I dropped a button on the SOViewController's view in IB and wired the pushMe: action to it. I also created another UIViewController-based class called JunkController and dropped a "Junk" label on it's view in IB -- that's all I did in IB. In the SOViewController's viewDidLoad:
navController = [[[UINavigationController alloc] init] retain];
navController.navigationBar.barStyle = UIBarStyleBlackOpaque;
navController.toolbarHidden = YES;
UITableViewController* tvController = [[UITableViewController alloc] init];
UITableView* tv = [[UITableView alloc] init];
tvController.tableView = tv;
tv.delegate = self;
tv.dataSource = self;
[navController setViewControllers:[NSArray arrayWithObject:tvController]];
In the pushMe: action implementation:
[self presentModalViewController:navController animated:YES];
Implemented the tableView delegate and datasource methods; for selection:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"row selected");
JunkController* junk = [[JunkController alloc] initWithNibName:#"junkcontroller" bundle:nil];
[navController pushViewController:junk animated:YES];
[junk release];
}
This should yield an app that surfaces a screen with a "Push me" button. When that button is pressed you should get an animated modal navigation-based table view -- mine had one row in it that contained a label "select me". Touching this row should animate the junk controller into view.
There is no need to make setupViewController a declared property in this view controller. Also, I could be mistaken but I thought "controller" was a reserved name in Cocoa, I'd change that name. So make sure you have registered with the UITableViewDelegate and use - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath to hook into and push your new view controller as follows:
SetupViewController *detailViewController = [[SetupViewController alloc] initWithNibName:#"SetupViewController" bundle:nil];
detailViewController.title = #"Setup";
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Goodluck!

UITable View Issue,

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