How to call UINavigation controller in objective c - objective-c

I am trying to implement facebook like sliding view without using any framework. What i am doing was i created UINavigation Controller view (say NVC1) in app delegate and i loaded a table view in it. I am also creating another navigationviewcontroller (say NVC2) on top NVC1. i placed a bar button item at the top left of NVC2. when i click on the bar button in NVC2, it will slide to side of the screen (i am animating manually), so that it will reveal the NVC1 that is behind NVC2. As already said NVC1 contains table view. If i click the table view cell in NVC2, it should show/animate over NVC1. How can i do that or is there any way to do that.

If you're using iOS 5, use storyboarding, create a nav controller, add your VC with tableView, create a second VC then right-click-drag from the 1st VC's tableView's cell to the 2nd VC & select "push". It will then all happen automagically! Sounds convoluted, but once you've done it a couple of times it's so much easier than messing around with code. On the other hand, sometimes you need to code it - if you really need to & you're still stuck, let me know & I'll post some code for you.

Implement the method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath and write SecondViewControllerNVC2 *objectNVC2 in .h file
it's look like following
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!objectNVC2) {
objectNVC2 = [[SecondViewControllerNVC2 alloc] initWithNibName:#"SecondViewControllerNVC2" bundle:nil];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
[self.navigationController pushViewController:objectNVC2 animated:YES];
}

Related

Dismiss a UISearchController View and Dissmiss UITableView to get to the root view controller

Context: I am creating an IOS application in Objective C with the ArcGIS Runtime SDK. My root view controller is a map. I have the option to create spatial bookmarks and view them in a table view that is pushed over the view. I have a UISearchController on the table view to be able to filter out the bookmarks. If you select a bookmark without searching, you are automatically panned to that location. This is done by popping all view controllers, and loading the root view controller with a flag for the bookmark variable to set as the starting extent.
I would like this same functionality with the searchController table view.
However, I am either unable to dismiss the searchController and the bookmark is zoomed to, or the search controller is dismissed, and the user is brought back to the initial table view.
What I have so far:
In the didSelectRow method on the searchController TableView:
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Accept the spatial envelope and save it to the shared variable to be passed to main view controller
//Now dismiss the searchController and call method to zoom to bookmark
[self.navigationController dismissViewControllerAnimated:NO completion:^{
//reference to shared instance method
[[BookmarksTableViewController sharedBookmark] zoomToBookmark];
}];
In BookmarksTableViewController.m
-(void)zoomToBookmark{
UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:#"viewController"];
[self.navigationController pushViewController: myController animated:YES];
//clear the navigation stack
self.navigationController.viewControllers = [[NSArray alloc] initWithObjects:myController, nil];
}
To me it seems like this should work, but all that happens is the UISearchController is dismissed, then the table view is not dismissed, and I am back where I was before I entered search text.
Any thoughts on a better way to dismiss the UISearchController or how to get back to my root view controller?
Hope you mean to this answer
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self dismissViewControllerAnimated:NO completion:nil];
}

pushViewController is not pushing

I was using initWithNibName to push the cells to detail views but I want to use single storyboard rather than having numerous nib files. The below code is supposed to push the view to subcategoriesViewController when the cell is clicked. the cells are dynamic from json data.
Its not giving any errors. Do you think its an issue with navigation control? Just to test, I added a button on this view and it works; when I click it, it does push to next view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
subcategoriesViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"subcategoriesViewController"];
controller.CATNAME = [dict objectForKey:#"C_NAME"];
controller.CATNUMBER = [dict objectForKey:#"CAT_ID"];
[self.navigationController pushViewController:controller animated:YES];
// [controller release];
}
Okay I think I have found the cause; but don't know how to fix it.
The tableview in this controller is actually a subview of a viewController. I duplicated these files and created a new view which is a TableViewController. This code, when used in the TableViewController does the job, but it doesn't do it when used in a controller where the tableview is a subview of a ViewController.
I want the table to be a subview because I want to put an image above the table. So, I think the problem here is this line:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
It does not reference the table in the view. Can anyone tell me how to modify this so it would reference the table within the view?
If didSelectRow... is not being called then your view controller is probably not set as the delegate of your table view.
This is set up for you automatically when using a UITableViewController but you have to explicitly do it when using a standard view controller.
An answer to your problem is often that self.navigationController is in fact nil because there is no navigation controller for your view. You perhaps have to get a pointer to the navigation controller of your projet and push your view on it.

Why NavigationController is not pusing the view?

I spent almost a day with this issue, someone please help me out! I'm trying to push the view from a tableview controller. It's not responding.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NewsDetailViewController *ndvc = [[NewsDetailViewController alloc] initWithNibName:#"NewsDetailViewController" bundle:nil];
[self.navigationController pushViewController:ndvc animated:YES];
}
I am guessing that your self.navigationController is nil. And from the comments I get that you do not use a Navigation Controller. I would say, create a Window Based Application with the Navigation Controller as the rootViewController and inside that, add the tableView to the view of the navigationController and then you should have no problem.
Your NewsDetailViewController likely overrides initWithNibName function. Use breakpoints to see why this is returning nil. Make sure you are passing the right NIB file name (i.e. make sure NewsDetailViewController.xib exists in your project)

Unable to display the detail view on selecting a row in TableView with a UITabBar

I am using a Navigation based application.The third view in my flow has a UITabbar added.On clicking one of the tabs a TableView is displayed.On selecting a row of this TableView I wish to display another view.
My code works fine to the point of displaying the different views on clicking the tabs.When I select a row of the TableView nothing is displayed.I use a plist to populate the tableView. I added the following code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PropertyRegistration *dvController = [[PropertyRegistration alloc] initWithNibName:#"PropertyRegistration" bundle:[NSBundle mainBundle]];
//dvController.selectedCountry = selectedCountry;
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
Can someone help?
I assume the third view controller is a UITabBarController which is working fine. But your root controllers in each tab, are you sure that they are UINavigationControllers? They (or at least the one containing your table view) need to be.
If your third view controller is not a UITabBarController, I'd recommend that you change it to be so. Then your structure would be something like:
UINavigationController: pushes through two UIViewControllers, then a UITabBarController (your third).
UITabBarController contains some view controllers, one or more of which is a UINavigationController. This navigation controller has a UIViewController as it's root view controller, and has other controllers pushed onto it.

Loading a subview after clicking a tableCell

So I am trying to add in to my current Xcode project a table view which, whenever you click on a cell, whichever one it is, a new subview is added to the window. I will use global variables and the didSelectRowAtIndexPath to pass data on.
As it stands, I have my table view drawn on screen with the correct data inside. What I want to happen is when I click, a new subview is added but i cannot seem to get this to work.
I have tried adding the "addSubview" inside the didSelectRowAtIndexPath method itself and this did not work and I have tried declaring a separate method that loads a subview called 'loadDetails' then calling it with [self loadDetails] when a cell is selected but it wants an id after the call and I don't know what to pass in.
I have elsewhere in my project used the line:
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
But I can't see how to adapt this to the tableCell unless I could somehow add a new button over the cell? I really don't know.
If anybody has any other ideas of how to solve this problem, that would be great.
Thanks,
Matt
EDIT:
Problem is now solved, was a really stupid mistake, I forgot to link the view on the xib I was moving to, to the view created programmatically in my header file
try using presentModalViewController to show your view, and then dismiss it from the modalViewController:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailView *detailView = [[DetailView alloc] initWithNibName:#"DetailView" bundle:nil];
[self presentModalViewController:detailView animated:YES];
}