How to load a table from a .nib when an item in a previous table is selected? - objective-c

At the moment, I have an iOS app that starts out with a NavigationView (root view) and a table contained in the root view below the navigation bar. I am attempting to load another view (hoping to make it another table) from a .nib file when the first row in the original table is selected. How can I do this?
Any help or advice would be appreciated. Thank you very much.

You need to make use of the UITableViewDelegate method, tableView:didSelectRowAtIndexPath:
Ensure that your tableview's delegate is set to your view controller inside Interface Builder, or if you are not using interface builder..
[tableView setDelegate:self];
Your view controller will then adopt the UITableViewDelegate protocol and respond to tableView:didSelectRowAtIndexPath: when a row is selected.
Loading your new view when the first row is selected will be implemented like so..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0){ // the first row
MyView *myView = [[MyView alloc] init];
[self.navigationController pushViewController:myView animated:YES];
[myView release];
}
}

Related

slide out menu move to another view controller

I followed this great tutorial on a slide out menu using UIKit Dynamics, Slide Out Menu. The code has been slightly modified to reduce duplication of code. I'm handling the touch event in the MenuComponent Class. Now, I'm trying to move to another view controller when the item is selected. The menu is created in code so I can't use segue's.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];
[self toggleMenu];
self.isMenuShown = NO;
if(indexPath.row == 0){
//move to the testViewController
}
How do you remove the current view and present a new one? My hierarchy is a navigation controller then my testViewController.
Edit: I did find this code which I tried, but my problem is the when the menu is present and I try to present the view I get an error:
testViewController *test = (testViewController*)[storyboard instantiateViewControllerWithIdentifier:#"testViewController"];
[self presentViewController:test animated:YES completion:nil];
Warning: Attempt to present <testViewController: 0x7c095470> on <MenuComponent: 0x7ae4ce50> whose view is not in the window hierarchy!
I was able to figure it out by creating a delegate for the MenuComponent and then pass the view like so:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController * test = [storyboard instantiateViewControllerWithIdentifier:#"test"] ;
[delegate didCallViewController:test];

iOS - Connect UITableViewCell to another ViewController Programmatically

I have programmatically created a tableView populated it with some rows. However, I was wondering upon tapping one of these cells how could I navigate to another view controller while passing data to the other viewController as well?
This is what I filled each cell with:
cell.textLabel.text = [NSString stringWithFormat:#"#%#", currentAccount.username];
How do I pass currentAccount.username to another viewController I just created? I am not using storyboards as I had created the UITableView programmatically. However, I have created another view controller called FeedViewController.
In your table view delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
you would instantiate your FeedViewController, pass any data to it using its properties and then display it.
Something like:
FeedViewController* feedVC = [[FeedViewController alloc] init];
feedVC.username = currentAccount.username
[self presentViewController:feedVC animated:YES completion:nil];

Transition to a view in table with dynamic cells

I create tableview and I fill the table dynamic data.
How to create transition between cell and another view.
Сells are filled with the names of files in the folder documents.
I use storyboard.
App for iPad.
You can make transition from cell to another view using following code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
anotherView *obj =[[anotherView alloc]initWithNibName:#"anotherView" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
}
this method is a delegate method of tableview and when you will select any cell ,it will be called and will go to another view

Accessing UITableViewController > UIView > UIView?

Can anyone tell me if this is possible?
I have a setup a UITableViewController which consists of a number of cells, if you select one of these cells you are taken to a new viewController using pushViewController (see below)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSLog(#"CELL__: You tapped the row ... %#", [list objectAtIndex:row]);
TestController *testController = [[TestController alloc] init];
[[self navigationController] pushViewController:testController animated:YES];
[testController release];
}
If in the implementation for "TestController" I would like to refer back to [self navigationController] (or maybe to add yet another view) is there any way to do that. My problem is that I need to access [self navigationController] to push further views and I don't know how to do that from the bottom controller?
Does that make sense?
Gary
From within TestController you reference the same UINavigationController via [self navigationController] as well.
EDIT to elaborate after comment:
The navigationController property is a property of UIViewController. If the controller is contained within a UINavigationController then it's own navigationController property will be a reference to that container UINavigationController. The same applies for tabBarController and splitViewController.

My table view does not navigate to another uiview page. What might be wrong?

My table view cells have the ContentView as the Labels. When I click on them to navigate to another view whose viewController is as shown does not navigate.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailedWebViewController *detailedWebViewTab1=[[DetailedWebViewController alloc] initWithNibName:#"DetailedRssWebView" bundle:Nil];
[self.navigationController pushViewController:detailedWebViewTab1 animated:NO];
[detailedWebViewTab1 release];
}
on tap it stays where it is highlighting the table in blue.
the object for the XIB is being created but cannot navigate to it.
Try to check in debugger if your detailedWebViewTab1 is really not nil. It seems to be so according to your description.