I am new to iPhone development, and I want to move to another page when the user clicks on a particular row. So, if they click on first row, I want the page to redirect to t
This was the one the things that I got problem when I first start. Here is my code that I use for this. In subviewcontroller I have my own constructor like
-(id)initWithName:(NSString*)naMe
{
name=naMe;
return self;
}
And in didSelectRowAtIndexPath
Delegate method Of UITableView
. I alloc it
MyListView mylistview=[[MyListView alloc] initWithName:@"name"];
[self.navigationController pushViewController:mylistview animated:YES];
[mylistview release];
NSInteger row = indexPath.row;
UIViewController *newFrontController = nil;
if (row == 0)
{
YourViewController *yourViewController = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];
newFrontController = [[UINavigationController alloc] initWithRootViewController:peopleViewController];
[self.navigationController setNavigationBarHidden:YES];
} else if(row == 1){
//do your code
}
do this in didSelectRowAtIndexPath in tableView.
@kashyap in didSelectRowAtIndexPath
delegate of the UITableView
you have to check the conditions that on which indexPath
you are clicking and open the viewControllers
you had made accordingly
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
switch (indexPath.row) {
case 0:
[self.navigationController pushViewController:firstViewController animated:YES];
[firstViewController release];
break;
case 1:
[self.navigationController pushViewController:secondViewController animated:YES];
[secondViewController release];
break;
}//Likewise do for the no of rows you have in your `UITableView`
Hope you get my point.....Good Luck!