Trying to push new controller into navigationController, Not sure why it is not woking.
1) I checked the instance of secondViewController also does not work.
2). tried suffixing '.xib", also not working.
3) Tried bundle:nil also not working.
I am using ARC. Can someone point out what is the issue here ?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#" YOU SELECTED ROW ..");
secondViewController *secController = [[secondViewController alloc] initWithNibName:#"secondViewController.xib" bundle:[NSBundle mainBundle]];
NSLog (#"View Controller %# ", secController);
[self.navigationController pushViewController:secController animated:YES];
}
I edit your code just try this.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#" YOU SELECTED ROW ..");
secondViewController *secController = [[secondViewController alloc] initWithNibName:#"secondViewController" bundle:nil];
NSLog (#"View Controller %# ", secController);
[self.navigationController pushViewController:secController animated:YES];
}
You don't need to pass the bundle in if the nib is located in the main bundle. Passing in nil will work, so change this:
[[secondViewController alloc] initWithNibName:#"secondViewController.xib" bundle:[NSBundle mainBundle]];
To this:
[[secondViewController alloc] initWithNibName:#"secondViewController" bundle:nil];
You can also take advantage of the fact that UIKit will look for a nib with the same name as the class and pass nil in for the nib name.
Do you intailize navigation controller? Check self.NaviagationController is it in memory ? May be 0*0
Related
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
Here is the code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
[DrinkDetailViewController release];
}
I want to have a back bar to go to my root view from the detail view. How do I do it?
There's 2 things that look a little weird here... hopefully fixing em will make the back btn show up:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
//[self.navigationController popToRootViewControllerAnimated:YES]; <-- you just pushed a viewController onto the stack, and you're immediately removing it here and going to the root
[detailViewController release]; //<-- you want to release the *instance* that you created... not the Class
}
The UINavigationController should take care of the back button for you as far as I know. If not, I would check to see that everything is wired up correctly in your xib (if you have one). Good Luck!
With your code, it will still push to the DrinkDetailViewController but the' popToRootViewController is totally unnecessary. You should delete the line like follows..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DrinkDetailViewController *detailViewController = [[DrinkDetailViewController alloc] initWithNibName:#"DrinkDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
And I believe, the reason your back button does not show up on the nav bar is because you didn't put any title in your root view. You can put this code on you viewdidload method on the root view.
self.title = #"Your Title";
I am new to iPhone development, and I want to move to another page when the user clicks on a particular row. So, if they click on first row, I want the page to redirect to the first view controller, and so on. Each row has its own view controller.
first of all you don't need to set different view controller for each row (unless you have a very good reason for doing that).
the correct way is to set 1 view controller that will fit all the cells in the raws and change its data according to the selected row.
the way you do that is:
in the - DidSelectRowAtIndexPath function in your implementation file you shuld:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//allocate your view controller
DetailedViewController *detailedViewController = [[DetailedViewController alloc] init];
//send properties to your view controller
detailedViewController.property1 = someProperty1;
detailedViewController.property2 = someProperty2;
//push it to the navigationController
[[self navigationController] pushViewController:detailedViewController animated:YES];
[detailedViewController release];
}
i do recommend that you will start by using apple examples, they are great and there are a lot of them :
http://developer.apple.com/library/ios/#samplecode/TableViewSuite/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40007318
Good luck
#kashyap in didSelectRowAtIndexPath delegate of the UITableView you have to check the conditions that on which indexPath you are clicking and open the viewControllers you had made accordingly
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:firstViewController animated:YES];
[firstViewController release];
break;
case 1:
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
break;
}//Likewise do for the no of rows you have in your `UITableView`
Hope you get my point.....Good Luck!
Dig into the docs:
http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/TableView_iPhone/ManageSelections/ManageSelections.html#//apple_ref/doc/uid/TP40007451-CH9-SW6
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case "X"
// Allocate the viewController
[navigationcontroller.pushViewController:"yourviewcontroller" animated:YES];
[release "yourviewcontroller"];
break;
default:
break;
}
}
EDIT: Didn't realize of what you're trying. As shani said, you should not create a viewcontroller for each row if there is no need to. Try changing the datasource for each row but using the same viewcontroller. So forget this implementation.
Easy:
Create and push your view controller in this delegate function:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
It sounds like using a UINavigationController is what you want.
You then push your "first view" on to the navigation controller's stack from the table view, e.g., from you UITableView delegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// indexPath.row == 0
FirstViewController* firstVC = [[FirstViewController alloc] initWithNibName...];
[self.navigationController firstVC animated:YES];
[firstVC release];
...
}
This was the one the things that I got problem when I first start. Here is my code that I use for this.
In subviewcontroller I have my own constructor like
-(id)initWithName:(NSString*)naMe
{
name=naMe;
return self;
}
And in didSelectRowAtIndexPath Delegate method Of UITableView. I alloc it
MyListView mylistview=[[MyListView alloc] initWithName:#"name"];
[self.navigationController pushViewController:mylistview animated:YES];
[mylistview release];
NSInteger row = indexPath.row;
UIViewController *newFrontController = nil;
if (row == 0)
{
YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:#"YourViewController" bundle:nil];
newFrontController = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
[self.navigationController setNavigationBarHidden:YES];
} else if(row == 1){
//do your code
}
do this in didSelectRowAtIndexPath in tableView.
You can move to another page when user tap on row by simply making segue by "Control Drag" from cell to ViewController and make segue type "Push".
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
So I am trying to simple traverse to the next level of a table view by doing this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1) {
FiltersController *aFiltersCont = [[FiltersController alloc] init];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:self animated:YES];
}
}
is there any reason why this would not be pushing the controller? I had a similar problem before, but solved it by displaying the view modally. However, this time, this is in a popover and needs to slide to the next screen inside that popover. Any Ideas? Thanks in advance.
OK I am going to put some more source up here to try and help...
Inside the main view controller I have this code to make the popover from a button:
// Create and configure the filters controller.
FiltersController *aFiltersController = [[FiltersController alloc] initWithStyle:UITableViewStylePlain];
self.filtersController = aFiltersController;
filtersController.appDelegate = self.appDelegate;
UINavigationController *filtersNavController = [[UINavigationController alloc] initWithRootViewController:filtersController];
UIPopoverController *filtersPopover = [[UIPopoverController alloc] initWithContentViewController:filtersNavController];
self.filtersPopoverController = filtersPopover;
filtersPopoverController.delegate = self;
and then I have the code I first posted in my filtersController class. Does that help at all?
[self.navigationController pushViewController:self animated:YES];
Should be
[self.navigationController pushViewController:aFiltersCont animated:YES];
If you are just displaying your sublcass of UITableViewController inside a UIPopoverController, the UINavigationController will not be created for you automatically. You may need to modify the code where you are creating the UIPopoverController with something like this:
MyTableViewController *table = [[[MYTableViewController alloc] init] autorelease];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:table] autorelease];
myPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
Then you should be able to push and pop navigation controllers on the stack no problem.
you are pushing self which is a reference to the current view controller. you should change the line with the push to the following if aFiltersCont is the viewController you are trying to drill to.
[self.navigationController pushViewController:aFiltersCont animated:YES];
You might be confused about the index. The first index is 0 not 1, so maybe you want indexPath.row == 0?
Also, you should release aFiltersCont before returning (you're leaking a FiltersController and anything it owns every time you run this method.
So maybe this?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
FiltersController *aFiltersCont = [[[FiltersController alloc] init] autorelease];
aFiltersCont.displayedFilters = [appDelegate.groupedBusiness allKeys];
aFiltersCont.currentLevel = self.currentLevel + 1;
[self.navigationController pushViewController:aFiltersCont animated:YES];
}
}