i have an application where a there is a root view controller which pushes another a view controller into view. this view controller shows a table. when a cell is selected, it pushes to another view controller.
The first push works, but the second doesn't.
Here is my code for the selection of the cell in the table:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TwoViewController *two = [[TwoViewController alloc] initWithNibName:#"TwoViewController": bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:two animated:YES];
[two release];
Any idea what i've done wrong? the codes I've used for both pushes are nearly identical...
I've tried this with putting this code in the touchUpInside event for a UIButton as well, but it does not work.
My guess is that there is no navigationController to push the view, but I don't know.
Please help!
Did you change the -initWithNibName:bundle method on TwoViewController? My guess is it doesn't initialize correctly (i.e.: the method doesn't initialize the super class correctly).
Edit: I think I found the error, it's kind of obvious, actually.
Please check this code you posted:
initWithNibName:#"TwoViewController": bundle:[NSBundle mainBundle]];
The error is near the #"TwoViewController": string, an extra semicolon that should not be there, change it to:
initWithNibName:#"TwoViewController" bundle:[NSBundle mainBundle]];
Log both 'two' and self.navigationController,
NSLog(#"two = %#", two);
NSLog(#"self.navigationController = %#", self.navigationController);
First you'll get to know, if one of them is nil (or both) and whether tableView:didSelectRowAtIndexPath: gets called at all.
Its navigation controller problem.Check it properly
If the new view controller is part of a view, it probably doesn't have a navigation controller. Check if navigation controller is nil before pushing.
Related
Problem: On selection of a particular uitableviewcell, a new DetailViewController should be opened. I have written the code in didSelectRowAtIndexPath but when I click on the cell it is showing me a runtime error.
I have tried calling with [self.navigationController presentModalViewController:jacket animated:YES ]; but when I do my view controller is not getting opened.
Another method I tried is by [self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];.
I have Specified Identifier in the segued has "JacketDetails" in the inspector but here I am getting a run yime error. I have Hooked Segue from UITABLEVIEWCELL to VIEWCONTROLLER.
When I click on the row JacketDetailViewController Should be open. I have Created Class JacketDetailViewController and for New ViewController I have set the class for this in the inspector.
I don't know why it is showing no segue , I have given the identifier in the inspector and properly hooked from tableviewcell to new view controller.
In JacketDetailViewController I want to display a list of Jackets. Presently it is blank ViewController.
My code is below. Would you please suggest a solution? I am a self-teaching beginner in this field. I might have made some minor mistakes. I have Googled my problem and tried to solve it but I have been stuck here for a few days.
TshirtDetailViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
[tableView deselectRowAtIndexPath:indexPath animated:YES ];
JacketDetailController *jacket =[[JacketDetailController alloc]init];
NSInteger index =indexPath.row;
NSLog(#"Row:%d",index);
NSString *titleString = [[NSString alloc] initWithFormat:[jackets objectAtIndex:indexPath.row]];
NSLog(#"%#",titleString);
jacket.title=titleString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];
// [self.navigationController presentModalViewController:jacket animated:YES ];
}
#end
Error in Console:
2013-01-07 10:52:21.020 KidsShopee[617:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x6a5fac0>) has no segue with identifier 'JacketDetails''
*** First throw call stack:
(0x13bf052 0x1550d0a 0xdd24b 0x3e8e 0xa671d 0xa6952 0x92e86d 0x1393966 0x1393407 0x12f67c0 0x12f5db4 0x12f5ccb 0x12a8879 0x12a893e 0x16a9b 0x1b08 0x1a65 0x1)
terminate called throwing an exception(gdb)
Try to open view with these lines:
YoutubeViewController *objYoutubeViewController = [[YoutubeViewController alloc]initWithNibName:#"YoutubeViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:objYoutubeViewController animated:YES];
[objYoutubeViewController release];
In place of YoutubeViewController give your view controller class name & change these lines
According to you & check.Ok if you using storyboard then try like below:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
bookmarkViewController *myVC = (bookmarkViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"bookmarkViewController"]
[self presentModalViewController:myVC animated:YES];
in place of bookmarkViewController give your controller name & check. in drag & drop view
controller in main storyboard give right class name like below images:
in place of my bookmarkViewController name give your view controller name that you want to open.
Don't call performSegueWithIdentifier:sender: on the navigation controller! Only your custom viewController can have segues. Call it on self.
Replace
[self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];
with
[self performSegueWithIdentifier:#"JacketDetails" sender:[tableView cellForRowAtIndexPath:indexPath]];
If you hooked up a segue in the storyboard from the table view cell to another controller, then you don't need any of this code at all to make the segue fire. You should be implementing prepareForSegue to pass the information you need to the detail controller, but no other code is necessary.
Based on the error you are getting "has no segue with identifier 'JacketDetails'", something is not right with your call to the segue. I have found that I have problems with seque names working properly unless I copy and paste from the name I gave the seque in the storyboard into my .m file. Even if the spelling and case is correct, I have found many times, copying and pasting has fixed the problem.
Can try with this-
JacketDetailController *jacket =[[JacketDetailController alloc]initWithNibName:#"JacketDetailController" bundle:nil];];///Change string as your nib name.
Then if its navigation base application-
[self.navigationController pushViewController:jacket animated:YES];
Then is its viewController base application-
[self presentModalViewController:jacket animated:YES];
My setup is using a storyboard in which I create a login, then a home screen in which the user can press a button to display their messages.
These are displayed in a table which is instantiated programmatically.
From this table I then want to press a row to go into detail about that row, but when i do this the view displayed is blank but all methods associated with the class are being fired (view did load, and so on).
I have literally tried 10 different ways from different solutions others had had suggested on their questions but nothing works.
Code to make new view and push it:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
messageDetail *messageDetailView = [[messageDetail alloc]initWithNibName:nil bundle:nil];
messageDetailView.message = [entityObjects objectAtIndex:indexPath.row];
[self.navigationController pushViewController:messageDetailView animated:YES];
}
ViewDidLoad of DetailView:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(#"Message Detail:\n%#",message);
messageTitle.text = message.message_title;
messageBody.text = message.message_xml;
}
I have tried using a segueIdentifier route and then intercepting the prepareSegue: to add data to the new view, but as the tableView is created programmatically there is no segue.
I have tried instantiating the view from storyboard via:
messageDetailView = [self.storyboard instantiateViewControllerWithIdentifier:#"MDV"];
But the app crashes as there is no view with identifier, even though i set the identifiers.
You send nil as nib name, if you do not have a nib file do not allocate the message detail view with initWithNibName function.
Use raw init or initWithFrame. Whichever works for you.
Good luck
I basically did the same thing with this code here. Hope this helps
Detail_View *next=[[Detail_View alloc] initWithNibName:#"Detail_View" bundle:nil];
//These are just values that I needed to set before going to the next page.
//You can use this if you want to pass over the value of your table row
//otherwise ignore this
next.htmlContents= [[storage_array objectAtIndex:indexPath.row]objectForKey:#"title"];
next.titleText=[[storage_array objectAtIndex:indexPath.row] objectForKey:#"title"];
[self.navigationController pushViewController:next animated:YES];
I'm presenting a modalViewController with UIModalTransitionStyleCoverVertical and then, when the user selects a row of this modalView, I present another modalView as follows:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
CenterViewController *nextView = [[CenterViewController alloc] init];
nextView.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nextView animated:YES];
[nextView release];
}
The problem is that the transition style remains UIModalTransitionStyleCoverVertical no matter what type of transition style mode I initialize for this second modal view controller.
Am I missing something relevant?
Thanks in advance.
UIModelPresentaionStyle is used to tell iOS you want it FullScreen or PageSheet..etc. , in your case you should use UIModelTransitionStyle .. so if you did like this it should work.
nextView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
I'd try removing the old one first, and then presenting the new one.
Doesn't sound like a great technique though. Why not have you first modal view controller be some sort of container controller, and present the new view with a flip.
losing sleep over this issue
My app hierarchy is ListVC1-->ListVC2-->DetailVC. [Working perfect]
and... SearchListVC-->DetailVC (the same DetailVC as above) [Issue is in this model]
The code in SearchListVC is almost same as ListVC2, with a difference that it contains a SearchBar, instead of a navigationBar, on top.
Also, please note that I am able to present the DetailVC as a ModalView, it is push that is not happening... the cell remains highlighted.
Here is the didselectrow code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Navigation logic may go here. Create and push another view controller.
if (indexPath.row<[smses count]) {
WebSMSDetailViewController *detailViewController = [[WebSMSDetailViewController alloc] initWithNibName:#"WebSMSDetailViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.smsList = allWebSMSes;
detailViewController.smsIndex = indexPath.row;
[detailViewController populateDetails];
[detailViewController release];
}
else {
if (indexPath.row<totalSMSes) {
pageNumber++;
[self loadNotes];
}
}}
I think the problem is somewhere else.
I have been googling for quite a while but couldn't understand the solutions posted, so please be a little descriptive... beginner here!
I suppose the problem is that, you dont have a navigation controller in the SearchListVC.
Like you wrote,
it contains a SearchBar, instead of a navigationBar, on top
Use a navigation controller with the SearchListVC and I think your problem is solved.
Cheers
You just create/use #property for the navigationBar
or u have to place the Navigationbar on the top of the view and place your search bar on the bottom of the navigationBar
I just filled my UITableView with Planets. I would like each cell clicked to open into a new Xib (if this sounds like the wrong approach please direct). I can get a secondviewcontroller working, its getting the thirdviewcontroller and fourthviewcontroller working? Thanks.
Place your main view controller (the one with the table) inside a UINavigationController. Then, when the user selects a row, push a new view controller onto it.
The following function will help. As Ben Gottlieb said your main view controller will need to be in a UINavigationController. You need to implement the delegate method for didSelectRowAtIndexPath and this is where you create the new controller for your new view and load it.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
YourViewController *controller = [[YourViewController alloc] initWithNibName:#"YourViewController"bundle:nil];
[[self navigationController] pushViewController:yourViewController animated:YES];
[yourViewController release]; // don't leak memory
}
Based on the row number you can decide which nib to load.