In my view-based application,it includes three views.First View(Main View) call second view.Second view call third view(detail view). I want to add home function in third view to go back first view(Main View).
Currently I add Home button in third view.But I don’t know how to write this function. The following is my code:
//In First view(main view)
//call second view(list view) in button click
-(IBAction) doctorList:(id)sender
{
if(self.doctorViewController==nil)
{
DoctorViewController *doctorView=[[DoctorViewController alloc] initWithNibName:@"DoctorViewController" bundle:[NSBundle mainBundle]];
self.doctorViewController=doctorView;
[doctorView release];
}
self.view addSubview:self.doctorViewController.view];}
}
//In second View(list view)
//Call third view in table cell click
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
DoctorItem *physician=[[DoctorItem alloc]init];
physician=(DoctorItem*)[self.tableDataList objectAtIndex:indexPath.row];
DoctorDetail *detail=[[DoctorDetail alloc]init];[tableView.superview addSubview:detail.view];
[physician release];
}
In third view,there is a button with label text ‘Home’
When user click this button,I want to add go back to first view(main view). I don’t know how to do that.
I didn’t see any mention of UINavigationControllers in Phoenix’s posting… so if I were fixing this code, I’d create an IBAction method like this:
and connect your button action to that method.
Also, I’d recommend subclassing UIView and not UIViewController for DoctorView and DoctorViewController. You don’t need the extra baggage that UIViewControllers bring if you’re just adding subviews onto the root view controller.