iPhone SDK: Pushed view controller does not appear - iphone

I want to add a detail view for one of the cells in my UITableView. I've created a new view controller SyncDetailViewController) and a NIB for the detail view. Didn't make many changes in the new class. Just added a label and outlet for it and connected nib with view controller.
Now I've added this code to my view controller (the one with UITableView, not the new one)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
SyncDetailViewController *dvController = [[SyncDetailViewController alloc]
initWithNibName:#"SyncDetailViewController" bundle:nil];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
The problem is that even if I select any row in the UITableView nothing happens. It doesn't produce any errors or warnings. I've added a breakpoint inside this method and it is reached so this code is executed.
Any ideas are much apprieciated.

"Nothing happens" sound so much like "sending a message to nil". Have you, by chance, checked that self.navigationController is not nil? Or that dvController is well initialized?

Related

didSelectRowAtIndexPath method does not load new View in iOS app code is inside

I have my first and normal view controller with a UITableView in it. The items that need to be displayed in those rows work perfectly.
Now comes the issue, if the user selects a row, I want a new view opened.
This view is called SecondViewController. so I have the .h, .m and .xib file named that way and it is of the UIViewController class.
I am using a CustomCell for the tableview could this be the issue?
I have #imported everything normally, and this is the code I am using in the method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animated:YES];
}
What on earth am I doing wrong? I have been looking at questions here for hours but nothing seems to be working.
Are you sure that self.navigationController is not nil?
Try to log it, From your code your problem is probably that, your self.navigationController is nil.
This class is pushed from another or are you starting the navigation in this class? If you are starting it in this class, this is your issue, you need to call the navigation that you created and not the one that is supposed to be with your viewcontroller.

iPhone: TableViewController nibName error with "initWithNibName:bundle:"

I have a dynamic cell UITableViewController and I want to push a specific View Controller when someone taps a cell. So I'm trying to use the pre-made method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
But when I go into the simulator and tap a cell, this is what I get:
"NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle [...] with name 'AffichageVotesQuestionDuMomentViewController'.
Within the method, I have this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
AffichageVotesQuestionDuMomentViewController *detailViewController = [[AffichageVotesQuestionDuMomentViewController alloc] initWithNibName:#"AffichageVotesQuestionDuMomentViewController" bundle:nil];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
}
AffichageVotesQuestionDuMomentViewController is a custom view controller I created myself. I also tried creating another random one and I get the same type of error. If I set the initWithNibName: to nil, it segues to a view controller that has the navigation bar on top, but that's completely black.
Now, I'm a beginning iPhone programmer and have a very poor understanding of nibs, nib names and such. Any help is appreciated. Also, I didn't do any segue in the storyboard or anything, since it seems I'm programmatically creating the view controller and pushing that way. If there's a good way to do it with segue though, I'm okay with that too (but I need to know the row of the tapped cell).
Thank you!
Because you're using IB storyboards you should do something lik this i think:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"mystoryboard" bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"AffichageVotesQuestionDuMomentViewController"];
... instead of using the "initWithNibName"-initializer which is used for the classical xib-based approach.

How to call a detail view from a table view within a Storyboard

I have following problem.
I have created a tab based Application with three Views and Viewcontroller.
FirstView(Start screen stuff), SecondView (Detailpage), ThirdView (Table for listing items).
(Connections from storyboard were set automatically).
In the third view a table is integrated and the content is displayed fine.
Now I would like to call the SecondView , when a row in the table is selected.
I also tried to add a forth View , outside the tabBar Controller, to get the Detailview, but this also did not help.
I have tried several tutorials and forum tips, but cannot get it working.
The class is set to the right ViewController, the identifier is set to detail.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
[self.navigationController pushViewController:detail animated:YES];
detail.label1.text = #"It is working";
}
When clicking on the row, it becomes blue, but nothing happens. No error Message , nothing.
Hope that you can help :-)
OK, I have tried to "optimize" my design.
Still have the tab based Views, but when clicking on a row in the table, a new (not linked in Storyboard) view should appear to display the details of the selected quote.
I have created a view in the storyboard and called it "detailzitat"
I have created a DetailViewController.h/m as UIViewcontroller class
I have set the custom class to DetailViewController
I import the DetailViewController.h in the ThirdViewController.h
I have modified the didSelectRowAtIndexPath method in ThirdViewController.h accordingly.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"detailzitat"];
[self.navigationController pushViewController:detailVC animated:YES];
}
and my DetailViewController.m looks like
#import "DetailViewController.h"
#implementation DetailViewController
#synthesize label1, labeltext;
- (void)viewDidLoad
{
[super viewDidLoad];
labeltext=#"JUHU";
label1.text=labeltext;
}
But again, nothing happens, besides the row gets blue.
I do not understand. If I am using this code in a Non-Storyboard project, it is working.
What am I doing wrong ? Is there any tutorial for this combination within Storyboards ? Have not found one for this approach yet.
Try to learn from the different tutorials on the web, but the biggest problem is, most ones are not for iOS5 and I am not so good to transfer then.
Hope to get some hints :-)
You might want to think about your design. If I am understanding your description correctly, the user will be on the third tab, tap on a row in a table, and then you will be switching them back to the second tab. A navigation controller might be a more natural, less confusing, choice there.
But in any case, something like this will work sometimes:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *detailVC = [self.tabBarController.viewControllers objectAtIndex:1];
detailVC.label1.text = #"It is working"; // <- this will not work consistently!
self.tabBarController.selectedViewController = detailVC;
}
The problem with this is that while the user is on that third tab, it's possible that the second tab view controller's view is unloaded (due to memory pressure for example).
It's also possible the user went from tab 1 to tab 3 immediately and therefore the 2nd tab's view isn't even loaded yet at all. (To even test the above code you would have to select tab 2 and then tab 3.)
If the second tab's view hierarchy is not loaded, the label1 property will be nil, and so this will not work. A better strategy would be to create a new #property of type NSString* on the DetailViewController. And set that property instead of trying to set the label1 directly.
Then in your viewWillAppear: for the DetailViewController you can update your labels as needed. At that point of course you can be sure that label1 is loaded and connected to the correct UILabel.
I hope that helps.
I think problem is at self.navigationController. If your view is not inside the navigation controller this will not work. So what you do is create a new navigation controller object there and then use it to show your detail view.

How to go from a view to another view controller (iphone)

I have a table view in a view controller (view based application), once a user selects one of the cells it should load another view.. I tried the navigation controller thing but that resulted in a huge failure along with 5-6 hours wasted (it crashes when I try to pushViewController onto the nav. controller). Is there anyway to move from one view controller to the other? Keeping in mind I need to send over the selected cell (a string)
Thanks
Edit:For those curious, I created another project as a navigation based application. Everything is working now.
Thanks all for the help.
You want to implement the UITableView delegate method didSelectRowAtIndex. Here's an example:
- (void)tableView:(UITableView *)aTableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[detailViewController setData:[tableViewData objectAtIndex:[indexPath row]]];
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
}
In your DetailViewController.m file, once you're finished with it, simply use
[self dismissModalViewControllerAnimated:YES];
to pop it off the stack.

Search Display Controller does not show searchBar

I created a simple TableViewController using the template offered by xCode.
Then I open the xib file of the TableViewController with Interface Builder and I drag/add a uisearchdisplaycontroller on the top part of the tableView.
xCode automatically creates and link all the outlets.
I save the xib file and I run the app but the searchBar is not displayed!
What else should I do to make appear the searchBar?!?
THANK YOU VERY MUCH!!!
I was having this exact issue. I would drag the search bar, it would "snap" into place on the table as a header, but it would never show.
I found that when you are presenting the next View you need to initWithNibName:
Example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewSubclass *dvc = [[UITableViewSubclass alloc] initWithNibName:#"UITableViewSubclass" bundle:nil];
[self.navigationController pushViewController:dvc animated:YES];
[dvc release];
}
This is also assuming you dragged the SearchDisplayController into the xib file. It will do all the necessary connections for you.
Hope that helps.