从子视图中删除视图

发布于 2024-08-24 18:26:22 字数 1264 浏览 8 评论 0原文

我有一个使用应用程序内功能的应用程序。

-(void) completeTransaction: (skPaymenttransaction *)transaction{



}

当上面的方法被调用时,我想删除所有子视图并返回到我的主菜单窗口(我的应用程序中的第一个视图)。

谁能建议最干净、最好的方法来做到这一点?

干杯

编辑:

只是为了让事情变得清楚,

我不确定这是否有什么不同,但我有我的主菜单屏幕,然后我用输入按钮执行以下操作。

UIViewController *controller = [[UIViewController alloc] initWithNibName:@"NibFile" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];

然后我有一个带有按钮的主屏幕,然后当用户点击它时,它会向他们呈现另一个模态视图控制器,如上所述。在此视图上有一个按钮,上面写着“购买”。他们使用点击这个,然后 StoreKit 开始工作,一旦付款完成,我想摆脱上面的两个模式控制器并留下主菜单屏幕。

任何想法..我尝试过如上所述

编辑2:

@Jordan 谢谢,

但不确定我是否正确执行此操作。我理解上面的代码。

但是当我启动我的应用程序时,我的应用程序委托会加载一个视图控制器,这是我的主菜单。然后我有一个按钮,可以将我带到另一个视图,如果用户单击未解锁的功能,那么它会显示另一个视图控制器,并打开商店。

因此,考虑到这一点,我如何返回主菜单。

我已经尝试过以下操作:

NSArray *subviews = [myAppdelegate.viewcontroller.view subviews]; 
for (int i=0; i<[subviews count]; i++) 
{ 
   [[subviews objectAtIndex:i] removeFromSuperview]; 
} 

但我得到了以下错误:

expected ':' before '.' ?

I have a App that uses the In App feature.

-(void) completeTransaction: (skPaymenttransaction *)transaction{



}

When the above method gets called i want to remove all subviews and go back to my main menu window (the first view in my App).

Can anyone suggest to cleanest and best way to do this?

Cheers

EDIT:

Just to make things clear

Im not sure if this makes a difference but i have my main menu screen, then iam doing the following with an enter button.

UIViewController *controller = [[UIViewController alloc] initWithNibName:@"NibFile" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];

Then i have a main screen with a button then when a user taps it, it then presents them with another modal view controller as above. On this view is a button that says BUY on it. They use clicks this and then the StoreKit does it business and once the payment is complete i want to get rid of the two modal controllers above and be left with the main menu screen.

Any Ideas.. ive tried as above

EDIT 2:

@Jordan Thanks,

But not sure if im doing this correctly. I understand the above code.

But when i start my app my app delegate loads a viewcontroller which is my main menu. Then i have a button that takes me to another view and on there is my features if the user clicks a feature that is not unlocked then it displays another view controller with the store on.

So with this in mind how do i get back to my main menu.

I have tried the following:

NSArray *subviews = [myAppdelegate.viewcontroller.view subviews]; 
for (int i=0; i<[subviews count]; i++) 
{ 
   [[subviews objectAtIndex:i] removeFromSuperview]; 
} 

but i get and error along the lines of:

expected ':' before '.' ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风蛊 2024-08-31 18:26:22

这应该有效。

// view is equal to your main view    
NSArray *subviews = [view subviews];
for (int i=0; i<[subviews count]; i++)
{
   [[subviews objectAtIndex:i] removeFromSuperview];
}

This should work.

// view is equal to your main view    
NSArray *subviews = [view subviews];
for (int i=0; i<[subviews count]; i++)
{
   [[subviews objectAtIndex:i] removeFromSuperview];
}
冷…雨湿花 2024-08-31 18:26:22

如果您谈论的是 UIViewController 而不是子视图(它们是不同的),那么您可以使用:

 [self.navigationController popToRootViewControllerAnimated:YES];

您可以将 UIView 添加到 UIViewController,在这种情况下使用我上面的代码,或者您将视图(例如 PushViewController)放在顶部UIViewController 的,在这种情况下使用此处的代码。

If you're talking about UIViewControllers and not subViews (they are different),then you can use:

 [self.navigationController popToRootViewControllerAnimated:YES];

You're either adding UIViews to a UIViewController, in which case use my code above, or You're pushingViews (e.g. pushViewController) on top of a UIViewController, in which case use the code here.

毁梦 2024-08-31 18:26:22

我们必须将要删除的视图放在数组中,以便我们可以通过枚举的方式删除所有内容

 NSArray *ChildViews = [ParentView subviews];
 for (UIView *childView in ChildViews) {
   [childView removeFromSuperview];
 }

We have to get the views to be removed in an array so that we can remove everything by means of enumeration

 NSArray *ChildViews = [ParentView subviews];
 for (UIView *childView in ChildViews) {
   [childView removeFromSuperview];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文