TableView help pushing a custom view - iphone

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

Related

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

popOver table view

In my project , On clicking the button the string present in the button Action method should store in popover table view cell.
I cam able to store a single sting , to the first cell ....
And now my problem is i had Four buttons each button action consists of 4 strings , and now the should at a time to the popover table view ,,,
#import "SecondDetailViewController.h"
-(IBAction)viewButtonPressed:(id)sender
{
[super viewDidUnload];
//create the view controller from nib
self.tablePopoverController = [[[TablePopoverController alloc]
initWithNibName:#"TablePopover"
bundle:[NSBundle mainBundle]] autorelease];
////-------------------------------
myArray = [[NSMutableArray alloc] initinitWithObjects:myString,myString2,myString3,myString4,myString5,myString6,nil];
tablePopoverController.getingOrder = myArray ;
NSLog(#"table popo %#",myArray);
tablePopoverController.contentSizeForViewInPopover = CGSizeMake(250, 250);
//create a popover controller
self.popoverController = [[[UIPopoverController alloc]
initWithContentViewController:tablePopoverController] autorelease];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
-(IBAction)orderButtonPressed
{
myString = staterlable1.text;
[myArray addObject:myString];
NSLog(#"myArray%#",myString);
}
-(IBAction)orderButton2Pressed
{
myString2 = staterlable2.text;
NSLog(#"myArray%#",myString2);
[myArray addObject:myString2];
}
-(IBAction)orderButton3Pressed
{
myString3 = staterlable3.text;
[myArray addObject:myString3];
NSLog(#"myArray%#",myString3);
}
-(IBAction)orderButton4Pressed
{
myString4 = staterlable4.text;
[myArray addObject:myString4];
NSLog(#"myArray%#",myString4);
}
-(IBAction)orderButton5Pressed
{
myString5 = staterlable5.text;
[myArray addObject:myString5];
NSLog(#"myArray%#",myString5);
}
-(IBAction)orderButton6Pressed
{
myString6 = staterlable6.text;
[myArray addObject:myString6];
NSLog(#"myArray%#",myString6);
my Problem Is after clicking these buttons the myString1 - to - myString6 NSString objects Should Store into NSMutableArray so That i will display all the strings in the TableViewPopOverController which will popover when clicking the another button in the second detailViewController........
thanks in Advance......
The usual way to do this is to embed TablePopoverController in a UINavigationController. Then, in TablePopoverController when handling tableView:tableView didSelectRowAtIndexPath:indexPath push detailViewController into the UINavigationController.
For example, you could build Controller structure the following way (based on your example):
//create a popover controller
self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:[[[UINavigationController alloc] initWithRootViewController:initWithContentViewController:tablePopoverController] autorelease]] autorelease];
It is similar to your popover-creation code, put inserts a UINavigationController under the popover. Now, in TablePopoverController you should handle row selections the usual way with a UINavigationController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetaiViewController *detail = [[DetaiViewController alloc] init];
/* Configure detail using indexpath here indexPath
...
*/
[self.navigationController pushViewController:detail animated:YES];
}
This will work as expected (by pushing the new view into the UINavigationController) because we set controller structure with a UINavigationController.

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!

iPhone SDK: pushViewController crashing

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

commit object to next TableViewController

i got a tableview controller.
if a cell is selected i perform the following:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain];
// Push the detail view controller.
[[self navigationController] pushViewController:singleCatTableViewController animated:YES];
[singleCatTableViewController release];
}
i want to commit an object to the next view controller that slides in after this row is selected.
do i have to do something like this?
ablogSingleCatTableViewController *singleCatTableViewController = [[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain];
[singleTableViewController setMyObject:superDuperObject];
or is there an easier way to do something like that?
i need this object directly after this tableviewcontroller is initialized, to fill it with specific data that belongs to this object.
please give me some advices.
thanks
You can also pass the object to the next view controller when you init the view controller.
To do so, you need to implement your own initializer for the view controller.
For example:
- (id)initWithStyle:(UITableViewStyle)style superDuper:(SuperDuper*)superDuperObject {
if (self = [super initWithStyle:style]) {
superDuper = superDuperObject;
}
return self;
}
Then,
ablogSingleCatTableViewController *singleCatTableViewController =
[[ablogSingleCatTableViewController alloc] initWithStyle:UITableViewStylePlain superDuper:superDuperObject];