Load a new view on click of a button
I have placed two butto开发者_StackOverflown in navigation controller on click of each button it should open new view , how to load a new view on click of a button
Right-click the Classes group in the project window of Xcode and select Add->New File… Select the UIViewController subclass template from the Cocoa Touch Classes and click Next. Name the view FirstViewController (make sure that the Also Created flag is selected) and click Finish. You get two files (FirstViewController.h and FirstViewController.m). Right-click again the Classes group and choose Add -> New File… This time, select View XIB template from the User Interface under iPhone. Click Next and name the file FirstViewController.xib. Click Finish. Repeat the last paragraph for the second and third view (name them SeconViewController and ThirdViewController).
Right-click the Classes group in the project window of Xcode and select Add->New File… Select the UIViewController subclass template from the Cocoa Touch Classes and click Next. Name the view FirstViewController (make sure that the Also Created flag is selected) and click Finish. You get two files (FirstViewController.h and FirstViewController.m). Right-click again the Classes group and choose Add -> New File… This time, select View XIB template from the User Interface under iPhone. Click Next and name the file FirstViewController.xib. Click Finish. Repeat the last paragraph for the second and third view (name them SeconViewController and ThirdViewController).
When you're operating with Navigation Controllers, transferring to a new screen and returning to the previous screen is achieved with pushing and popping new ViewControllers on a stack. So, assuming you have a UITableView inside your Navigation Controller you simply add this line to didSelectRowAtIndexPath:(NSIndexPath *)indexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyNewController *controller = [MyNewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
}
精彩评论