I want to push a view when I click the cell of my tableview.The code is as followed:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView.tag == todoTableViewTag) {
NSLog(#"aa");
ViewControlleraaa* testvc = [[ViewControlleraaa alloc] initWithNibName:#"ViewControlleraaa" bundle:nil];
[self.navigationController pushViewController:testvc animated:YES];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
but it does not work at all.
I have
ViewControlleraaa.h ViewControlleraaa.m and ViewControlleraaa.xib
but I did nothing except creating them.
So where is the problem?
Create a 'generic' segue from your table view controller to ViewControlleraaa and use 'performSegueWithIdentifier'. If that approach is not possible to execute then you may want to try 'presentViewController' instead.
Try creating a manual segue from your table view controller to ViewControlleraaa. Then, as the answerer above me said, you can use performSegueWithIdentifier to call the segue. If you should ever need the table view controller to push any data to the ViewControlleraaa, you can do so using the "prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender" method. The destinationViewController property of "segue" is ViewControlleraaa.
Here's a link to a YouTube video, in case you need any additional help: https://www.youtube.com/watch?v=XApYtAlRDVE
Check self.navigationController is not nil then surly it will work fine.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ViewController *vc = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}
Related
I am new to iOS and I have created one tableList using xib file and when I click on tableList row, I want to push detail view controller but here didSelectRow is calling, but it's not pushing to details view controller. Please help me..
my code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
NSLog(#"Hello");
[tableView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *detailVC = [[DetailViewController alloc]initWithNibName:#"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailVC animated:YES];
}
I have a problem when clicked a row in a UITableView
I used this method didSelectRowAtIndexPath to catch when the user clicks on a row, but doesn't work normally.
the user must press and hold the row to execute the action but do not want it to be so.
Any idea what may be happening?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
Refunds *current = [refunds_view objectAtIndex:indexPath.row];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
DetailRefundsViewController *myVC = (DetailRefundsViewController *)[storyboard instantiateViewControllerWithIdentifier:#"DetailRefundsViewController"];
[self presentViewController:myVC animated:YES completion:nil];
}
Thanks.
Best Regards.
In my case, your code is instantly work, just modify class name and Storyboard Identifier.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
LJWDetailViewController *myVC = (LJWDetailViewController *)[storyboard instantiateViewControllerWithIdentifier:#"LJWDetailViewController"];
[self presentViewController:myVC animated:YES completion:nil];
}
I think, some of your codes are block this didSelectRowAtIndexPath: Method.
find out which controls are block this method
and set those control's delaysContentTouches Property by NO like this.
_imageScroll.delaysContentTouches = NO;
Sorry for Poor English :<
If you're using StoryBoards, then I think you're better off using a push segue directly from the TableViewCell to the ViewController you want in the Interface Builder (control click and drag from the TableViewCell to the ViewController). Make sure to give the segue a name (in my case below "showDetail"). Then implement the code below:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
[[segue destinationViewController] setDetailItem:object];
}
}
In my app I am using the following didSelectRowAtIndexPath method to go to a viewController, but I am working within an story Board, and an exception is thrown telling me that the nib file is not found. How should I change the method to open the new viewController without exceptions?:
//link to the next view
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
EmpresasTableViewController *detailViewController = [[EmpresasTableViewController alloc] initWithNibName:#"EmpresasTableViewController" bundle:nil];
detailViewController.title =[[categorias objectAtIndex:indexPath.row]objectForKey:#"idCategoria"];
detailViewController.categoriaDescription = [categorias objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailViewController animated:YES];
}
you have to make an identifier (detailViewController for example)for you ViewController in your storyboard and then instantiate like this your EmpresasTableViewController
EmpresasTableViewController *detailViewController =[self.storyboard instantiateViewControllerWithIdentifier:#"detailViewController"];
i hope that help you
Im working with table view controllers within story board.
I currently have one tableview controller embedded in navigation controller in my storyboard. This table view controller is linked to an ObjectiveC file.
Through code i can display another table view controller with the correct data using the tableView didSelectRowAtIndexPath method.
code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
[self.navigationController pushViewController:detailViewController animated:YES];
}
But if i try to add another table view controller in storyboard, associate it with an objectiveC view controller file and connect the first TVC to it, That table view controller is not shown upon running the code.
I need to customise the second table view visually and have tried to use a segue push...as follows:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"show"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
WorkoutType *workoutType = (WorkoutType *)[self.fetchedResultsController objectAtIndexPath:indexPath];
//WorkoutSetViewController *detailViewController = [[WorkoutSetViewController alloc] initWithWorkoutType:workoutType];
WorkoutSetViewController *destViewController = segue.destinationViewController;
destViewController.workoutType = workoutType;
//[self.navigationController pushViewController:detailViewController animated:YES];
}
}
But when i run this code, the second table view controller doesn't even load although the application doesn't crash.
Whatever I am doing wrong must be simple, any help would be appreciated.
Thank You
Simple You have to navigate through below code. (No need to set storyboard when you working in same storyboard ViewController)
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexpath.row==0)//for first row click
{
WorkoutSetViewController *objWorkoutSetVC=[[WorkoutSetViewController alloc] i nitWithNibName:#"WorkoutSetViewController" bundle:nil];
[self.navigationController pushViewController:objWorkoutSetVC animated:YES];
}
else if(indexpath.row==1)//for second row click
{
//Put code in which screen you have to navigate
}
}
Do NOT Alloc init your new view controller. Use this code instead:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
WorkoutSetViewController *detailViewController = (WorkoutSetViewController *)[storyboard instantiateViewControllerWithIdentifier:#"coolID"];
[self.navigationController pushViewController:detailViewController animated:YES];
For MainStoryboard write your storyboard name and for coolID write your view controller id name which you set in your storyboard.
I have started working with story board ,a new feature in iOS 5,so I started with a tabbed application,then I added a table view controller and filled the cells with some dummy data,now,the table has 4 cells,now on click of each cell,I want to open a newViewController,which will be diffrent for each cell,
So previously,I used to code this way
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if(indexPath.row == 0)
{
FirstViewController *settingsView =[[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 1)
{
SecondViewController *settingsView =[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
if(indexPath.row == 2)
{
ThirdViewController *settingsView =[[ThirdViewController alloc]initWithNibName:#"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:settingsView animated:YES];
}
}
But know,how shall I do it..please help me out
Thanks & Regards
Ranjit
Maybe this tutorial would help you?
http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-uitableview-tutorial.html
As I see this (performSegueWithIdentifier:sender:) should be the method to perform a new viewcontroller from the storyboard
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/performSegueWithIdentifier:sender: