I have a UIViewController that has UISegmentedControl that displays 3 other views depending on what segment is selected via:
- (void)segmentedControl:(SVSegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)index
{
if (index == 0)
{
MyTableViewController *myViewController = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil];
myViewController.view.frame = CGRectMake(0.,40.,self.view.frame.size.width,self.view.frame.size.height-40.);
self.theTableViewController = myViewController;
[myViewController release];
[self.view addSubview: self.theTableViewController.view];
}
But when I select a row from a cell on this view, it does not push to the next. This is because I’ve manually added that view controller’s view to the view hierarch so its not being managed by the navcontroller. I think I need to make a property or something can anyone chime in?
Edit:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SpecificExerciseTableViewController *specificExerciseTableViewController = [[SpecificExerciseTableViewController alloc] initWithNibName:@"SpecificExerciseTableViewController" bundle:nil];
specificExerciseTableViewController.exerciseArray = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"exercises"];
specificExerciseTableViewController.muscleName = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
NSString *muscleURL = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"musclePicture"];
specificExerciseTableViewController.muscleURL = muscleURL;
[self.navigationController pushViewController:specificExerciseTableViewController animated:YES];
[specificExerciseTableViewController release];
}
EDIT:
could you add more detail about your delegate? when do you set it? how is
didSelectRowAtIndexPathdefined?I guess that inside of
didSelectRowAtIndexPath,self.navigationControllerwill be nil, since that controller has not been pushed. So, you should access the navigation controller through the main view controller where you are adding the table view as subview.