How do I use tableview to navigate to new view/page/screen - view

So I have use tableview to make a list that works with the search bar, but now I want the sections in the tableview to navigate/go to a new view/page/screen when I press it, can anyone help me with this?

Here you go:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[self navigationController] pushViewController:[[SecondViewController alloc] initWithNibName:#"SecondView" bundle:[NSBundle mainBundle]] animated:YES];
}

Related

XCode Reusing UITableViewCells in Storyboard

I have a UITableViewCell in my project that I want to reuse in a few UITableViews. Is there a way to reuse them without setting up UILabels, etc each time in the Storyboard?
In cellForRowAtIndex, you can refer to the custom cell:
- (UITableViewCell *)tableView (UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = ...
cell.labelName.text = ...;
Return cell;
}
You need to create your UITableViewCell class and register it for your tables
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView registerClass:<RegisteredClass> forCellReuseIdentifier:<ReuseIdentifier>];
}

UITableViewCell unrecognized selector sent to instance

I'm creating a table view and custom view for my UITableView. Basically I have FirstViewController with table view and CustomTableViewCell. In custom cell, I had link all the controls to header and implements in the file which superclass with UITableViewCell. I'm creating a button, and want to programatically using "instantiateViewControllerWithIdentifier" for more flexibility in future. Here's come a problem :
Button being initialized
[self.playButton addTarget:self action:#selector(NavigationMethod) forControlEvents:UIControlEventTouchUpInside];
NavigateMethod
UIViewController *secondViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:nil]instantiateViewControllerWithIdentifier:#"SecondViewController"];
[(FirstViewController*) presentViewController:secondViewController animated:YES completion:nil];
Because everything is in UITableViewCell instead of UIViewController.
You're breaking Model View Controller methodology here... In FirstViewController you should have
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
MYCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[MYCustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; // might not be UITableViewCellStyleDefault
[cell.playButton addTarget:self action:#selector(navigationMethod) forControlEvents:UIControlEventTouchUpInside];
}
// all indexPath based tableViewCell changes here
return cell;
}
Now -(void)navigationMethod can go in your FirstViewController class also. Which will allow you to call
[self presentViewController:secondViewController animated:YES completion:nil];
or
[self.navigationController presentViewController:secondViewController animated:YES completion:nil];
Just to add in as well.. unrecognised selector sent to instance means in this case the method NavigationMethod is not found in your UITableViewCell subclass

Xcode: How to switch to another window using TableView?

the error ---> when i click the name the application crashes...
rectification---> when i click the name in table it should jump to another view...
my code is
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[ListArr objectAtIndex:indexPath.row];
ListData *oList = [[ListData alloc] initWithNibName:#"ListData" bundle:nil];
NSString *psCatId = [NSString stringWithFormat:#"%d",indexPath.row+1];
oList.psId = psCatId;
[self presentModalViewController:oList animated:YES];
[oList release];
}

mwfeedpaser detailview

I just started using xcode and OBJ-c this year.
I am using mwfeedparser for a app I'm making but would like to change the look of the detailview.
right now i'm using the demo app that came with mwfeedparser to change the detail view.
i would like the detail view to have labels instead of being a tableview
i have changed this code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
when i run the code the detailview doesn't even come up. am I doing something wrong?
thanks for your help.
btw when i do get this done I'll put it up on github incase anybody else needs it
enter code hereself.parsedItems = [[NSMutableArray alloc] init];
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item{
if (item) {
[self.parsedItems addObject:item];
}
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *detail = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
detail.item = [self.parsedItems objectAtIndex:indexPath.row];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detail animated:YES];
}

How to update detailViewController.detailItem from multi-level nav in rootViewController

this is my first post so please be gently.
I am using the basic Split View-based application within xcode, but have edited it so that the rootViewController does not simply update the detailViewController, but instead pushes a new UITableViewController (taskViewController) onto the navigation stack.
My problem is, that nothing happens when I now call the following from my taskViewController:
detailViewController.detailItem = [NSString stringWithFormat:#"Row %d", indexPath.row];
If I call this from rootViewController, instead of pushing a new UITableView onto the stack, it works.
Here is my code from rootViewController when a cell is selected:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TaskViewController *taskViewController = [[TaskViewController alloc] init];
taskViewController.title = [NSString stringWithFormat:#"Unit %d",indexPath.row];
[self.navigationController pushViewController:taskViewController animated:YES];
[taskViewController release];
}
Have I done something wrong here? Am I using the navigation controller correctly within the rootViewController of the UISplitViewController?
Your rootViewController can access detailViewController because it has a referance to it. if you push a new controller onto the nav stack, then its not automatically going to know about DetailViewController.
Have you NSLog'd detailViewController in your taskVC to see if it has a pointer?
You would typically set this when you are creating it like this:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TaskViewController *taskViewController = [[TaskViewController alloc] init];
taskViewController.title = [NSString stringWithFormat:#"Unit %d",indexPath.row];
taskViewController.detailViewController = self.detailViewController;
[self.navigationController pushViewController:taskViewController animated:YES];
[taskViewController release];
}

Resources