I have a UITableView in which I want to let user to click on the cell and use a sub view to display the detail information. I have tried this method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubMainViewController __autoreleasing *mSubView = [self.storyboard instantiateViewControllerWithIdentifier:#"mainSubView"];
[self presentViewController:mSubView animated:YES completion:nil];
}
This seems to be working, however, I couldn't get back to my table view, could anyone help me out?
Well it seems you want to load a detailview when user selects a cell and you want the user to be able go back to the previously view when back or some button like that is pressed. You need to use navigation controller for that. Here is the link to apple's doc http://developer.apple.com/library/ios/ipad/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
And here is a sample tutorial to get you started
http://razell.hubpages.com/hub/IPhone-Guide-Loading-a-detail-view
Hope this helps, let me know if you need any more help.
EDIT:
So according to your comment you are looking for a modal view to pop up over the view. Well here is a link to whole a lot of different ways to achieve that, and they all have example projects too so you can actually see how the trick is executed.
http://samwize.com/2012/12/06/7-ios-custom-popup-views/
In your SubMainViewController you need to dismiss the your current viewcontroller using
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
Related
I am trying to create push segue from view. Maybe image would be best for describing:
I started from sample ECSlidingViewController project (BasicMenu) and I am trying to expand first ViewController (Home) to another ViewController. I get it and I can go from selected row in tableView to the controller. But when I am in controller and I tap on Back I am at different screen from first one (it's blank screen with button at upper left). I guess I must set something more to get this working but I don't know what. Thanks
Updated:
Code from first view controller to go to next view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Find the selected cell in the usual way
UITableViewCell *cell = [self.searchResultsTableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:#"selectedSegue" sender:cell];
}
I found that the problem is with code in method didSelectRowAtIndexPath. When I removed it. The segue is performed well and I go to other view controller and when I tap on top left button I get back where I was. It's okay.
So I guess the real problem was with sender in performSegueWithIdentifier.
But I need send to new controller some information about selected row. So I used this answer.
Just Have an issue and a "miss" in my programming "capacity".
I've got a tableview controller with some data parsed from a json.
When you choose a "news" you to to the detail view with all data in it.
Everything is ok, but I add a "check" If you are logged or not.
And if not you are "redirected" to login screen.
I try to do it with a segue (modal). It's working, but when I do it, my "navigation" is broken, like if he "lost" he's path.
I try to do it programatically like :
LoginViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self.navigationController pushViewController:controller animated:YES];
But when I'm doing it like that, nothing happen, my "detail view controller" load without redirecting
and got that log:
nested push animation can result in corrupted navigation bar Finishing
up a navigation transition in an unexpected state. Navigation Bar
subview tree might get corrupted.
Did someone have a hint for me ?
Thanks
you are doing it all wrong. you need to study the very basic of seque programming (storyboard).
follow this link
LoginViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self.navigationController pushViewController:controller animated:YES];
in storyboard you already have a push segue, & again you are pushing loginviewcontroller. thats why you are getting "nested push animation" warning.
This isn't the normal way to do it. You would normally present that login view controller modally.
If this is just the way you want it you could do it using the following steps:
1) Connect your DetailViewController to your TableViewController (not from cell itself, but from that yellow icon which represents your ViewController at the bottom black bar). Choose push if you like and add the identifier to that Segue (for example, "DetailSegue")
2) Connect your LoginViewController to your TableViewController just like you connected your DetailViewController and add the identifier to that segue (for example, "LoginSegue").
Now, when the user clicks on some cell, you wish to check if session is still active, if it is you will do [self performSegueWithIdentifier:#"DetailSegue" sender:self];, and if it is not, you will do [self performSegueWithIdentifier:#"LoginSegue" sender:self];
Hope this helps, cheers.
it's pretty tough to understand what you want to do, the question isn't too clear.
If you want to link to a scene in your storyboard though, create a segue to this by ctrl + click & drag from the initial scene, then give the segue an ID (do this by clicking on the segue and using inspector to set an ID)
then in your tableview controller, where ever you are picking up your tab (assuming this is in the tableview delegate method) you can call the segue programatically
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"YOURSEGUEID" sender:self];
}
I have a ViewController, for example startingScreenViewController. I have a push segue from an item on this view to another view (someViewController) which is a ViewController that has a TableView (not TableViewController of course) in it. Now, without having a back button I want to go back to the first view by tapping on a cell in table view. I have written my cell delegate:
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
I tried using
[self.navigationController popViewControllerAnimated:YES];
and obviously it didn't work, since I don't have a navigationController. I even tried to segue back to the startingScreenViewController which was a stupid thing to do and also didn't work.
I'm in need of some help, and suggestions would be much appreciated.
I don't know how you manage to open someViewController with push segue without UINavigationController, but if it works, try to use this code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self dismissViewControllerAnimated:YES completion:nil];
}
And, of course, check, is your view controller delegate of table view.
The short answer is to not use a push segue when you don't have a navigation controller. That should not work at all, and the fact that it does work is an accident. There is no guarantee that it will continue to work in the future.
Use a modal presentViewController:animated:completion call, the dismiss it using the corresponding call.
I am stuck at this since 2 days now, searched almost 27 diff stackoverflow answers yet cannot do it
I want to manually push my view to a different view, I created a Segue with it with identifier gameView and tried using prepareForSegueWithIdentifier method but it doesnt works, always says my viewController cannot find a segue with identifier "gameView" even though it exists.
Here are some screenshots for better understanding:
Earlier on I was using same code which is in prepareForSegue (wasnt using manual push so no prepareWithIdentifier) since earlier I was pushing view from cell selection and it was working, but now I need to push the view manually due to implementing async tasks etc.
Any help on this will be appreciated.
After seeing your project I saw that u were using segue, and made a mess out of it which confused the program, I removed it and made the selecting system with the delegate method for UITableView
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
And then process some data and when its done I present the right ViewController using the method
presentViewController:(UIViewController *)viewController animate:(BOOL)animate completion:^{block}
ViewControllerYouWantToChangeTo *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"ID"];
[self presentViewController:vc animated:YES completion:nil];
ID refer to storyboard or the VC you want to change to
and instead of using
[self dismissViewControllerAnimated:YES completion:nil];//<-- this could cause a warning
use :
[[[self parentViewController] parentViewController] dismissViewControllerAnimated:YES completion:nil];
I'll be really grateful for any help with this - i've been trying to figure out how to change tabs on a tabbarcontroller from within a nested UITABLEVIEW as in RayWenderlich.com's tutorial on a pulse like scroller http://www.raywenderlich.com/4723/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-2 but am getting really stuck. I am using storyboards and xcode 4.4
I'm completely new to xcode as of a few weeks so I apologise if this is a newbie question. I have got the nested horizontal tableviews working fine as per the image in the link above but I want to use the images to switch to a new tab but can't - I think this is because the tableview is nested so I can't find the right reference to the tabbarcontroller in the hierarchy.
if I use ArticleListViewController.m didselect where the tutorial included comments seem to suggest to insertion navigation code will generate an NSLog output and change tabs ok but only using a tiny thin strip above the images (I discovered this by accident) but nothing happens with the images.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller
//THIS SELECTS WHEN CLICK THINSTRIP JUST ABOVE BUTTONS
NSLog(#"ARTICLELISTVIEWCONTROLLER check didSelect: %u", self.tabBarController.selectedIndex);
self.tabBarController.selectedIndex = 2;
}
the following code within HorizontaTableCell.m more appropriately generates an NSLog output when I click on the actual images but I can't figure out the tabbarcontroller reference that allows me to change tabs.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//the following line just generates an Error as follows: Property tabBarController not found on object of type 'HorizontalTableCell *'
self.tabBarController.selectedIndex = 2;
NSLog(#"HORIZONTALTABLECELL DIDSELECT");
}
Ive looked and looked for a way round this but can't figure it out. Found a mention of using appdelegate but not sure how to do this. can't post storyboard image as new user but has a tabbarcontroller with 4 navigation controllers coming out - the first is the ArticleListViewController menu and each of the others are viewcontrollers - one I hope to put a webview that loads a link/local page depending on the menu selected and the others for an about screen and an additional currently blank screen.
Please help!
thanks!
I'm guessing you have the tabBarController as a property in your app delegate?
You can reach your app delegate with:
[[UIApplication sharedApplication] delegate]
Cast that to your app delegate class and the compiler will not warn you for reaching at the tab bar controller. Like this:
((YourAppDelegate *) [[UIApplication sharedApplication] delegate]).tabBarController.selectedIndex = 2;
As for the tableview delegate method, ArticleListViewController sounds like the place where you'd want that. The cells should just be dumb views with minor presentation logic at most. If it is not getting called, make sure you've set it up as a delegate for the table view properly (in interface builder if you followed that tutorial you linked to).