开发者

How to return to the main view in a tab bar application

In a tab bar application I made a view controller for the second view. I put in an IBOutlet that is attached to a button. When the button is pressed, I want to return to the main view. This is wha开发者_StackOverflow中文版t I put, but it crashes.

-(IBAction) cancel
{
    [self.view removeFromSuperview];
}

How should this be changed?


If I understand you correctly you have an application based on or similar to the "Tab Bar Application" template, and on the second tab you want to have a button to move to the first tab.

You want to do something like tabBar.selectedItem = 0;

You probably need to connect the Cancel button to the Tab Bar controller itself, if this is not already the case.

EDIT: Here is an example, assuming your application is called "MyApp"

In class MyAppDelegate:

- (IBAction) cancel
{
    tabBarController.selectedItem = 0;
}

Drag the selector from the button to the "cancel" action of the app delegate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜