父视图控制器和模型视图控制器解除检测不起作用

发布于 2024-12-07 12:03:17 字数 647 浏览 0 评论 0原文

我有一个名为 ShowListViewController 的 UIViewController,它使用模态视图控制器将另一个视图推送到堆栈上:

AddShowViewController *addShowViewController = [[AddShowViewController alloc] init];
[addShowViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addShowViewController animated:YES]; 

然后,当 <代码>addShowViewController消失。

我认为此处找到的答案会起作用,但事实并非如此。我的方法 populateTableData 未被检测为可选方法。

本质上我的问题是:如何检测模态视图控制器何时消失,以便调用类中将其推入堆栈的方法?

I have a UIViewController called ShowListViewController that uses a Modal View Controller to push another view onto the stack:

AddShowViewController *addShowViewController = [[AddShowViewController alloc] init];
[addShowViewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:addShowViewController animated:YES]; 

I would then like to call my method populateTableData of the ShowListViewController class when the addShowViewController disappears.

I would think that the answer found here would work, but it doesn't. My method populateTableData is not detected as an optional method to use.

Essentially my questions is: How do I detect when a Modal View Controller disappears so as to call a method within the class that pushed it on the stack?

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

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

发布评论

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

评论(3

你又不是我 2024-12-14 12:03:17

这可能不是最好的解决方案,但此时可以做你想做的事。

在您的 showlistcontroller 中添加一个实例变量

BOOL pushedView;
@implementation ShowListViewController

,然后在进行模态演示之前将其值设置为 YES,就像

pushedView = YES;
[self.navigationController presentModalViewController:popView animated:YES];

在 ShowListViewController 的 viewWillAppear 中一样,您可以检测它是否出现,因为 pop 被解雇或不像

if (pushedView) {
    NSLog(@"Do things you would like to on pop dismissal");
    pushedView = NO;
}

This may not be a best solution, but can do what you want at this time.

In your showlistcontroller add an instance variable like

BOOL pushedView;
@implementation ShowListViewController

and before you do the modal presentation set its values as YES like

pushedView = YES;
[self.navigationController presentModalViewController:popView animated:YES];

in the viewWillAppear of ShowListViewController you can detect whether it is appearing because pop getting dismissed or not like

if (pushedView) {
    NSLog(@"Do things you would like to on pop dismissal");
    pushedView = NO;
}
风吹过旳痕迹 2024-12-14 12:03:17

我想你会喜欢这样的东西。

你在你的 modalVC 中创建一个委托,如下所示:

@protocol ModalViewDelegate <NSObject>

- (void)didDismissModalView;

@end

并在你的 MainVC 中实现它,如下所示:

@interface MainViewController : UIViewController <ModalViewDelegate>
{

然后你将在你的 modalVC 中创建一个委托属性,如下所示:

    @interface ModalShizzle : UIViewController
    {
        id<ModalViewDelegate> dismissDelegate;
    }

将 ModalVC 的 dismissDelegate 设置为 MainVC,然后创建委托方法。然而,在您关闭它之前,您将调用 ModalVC 做最后一件事。 (这是填充你的表)。您将在 MainVC 中调用数据,然后在关闭 modalVC 之前执行您想做的任何操作。

-(void)didDismissModalView
{
    //call ModalVC data here...
    //then do something with that data. set it to a property inside this MainVC or call a method with it.
    //method/data from modalVC is called here and now u can safely dismiss modalVC
    [self dismissModalViewControllerAnimated:YES];
}

希望它有帮助;)

I think you would like something like this.

You make a delegate inside ur modalVC like this:

@protocol ModalViewDelegate <NSObject>

- (void)didDismissModalView;

@end

and implement it in your MainVC like this:

@interface MainViewController : UIViewController <ModalViewDelegate>
{

Then u will make a delegate property in your modalVC like this:

    @interface ModalShizzle : UIViewController
    {
        id<ModalViewDelegate> dismissDelegate;
    }

You set the dismissDelegate of your ModalVC to your MainVC and then you make the delegate method. Before you dismiss it however you will call the ModalVC to do one last thing. (which is populate your table). You will call for the data inside your MainVC and then do whatever you feel like it, just before you dismissed your modalVC.

-(void)didDismissModalView
{
    //call ModalVC data here...
    //then do something with that data. set it to a property inside this MainVC or call a method with it.
    //method/data from modalVC is called here and now u can safely dismiss modalVC
    [self dismissModalViewControllerAnimated:YES];
}

Hope it helps ;)

纸短情长 2024-12-14 12:03:17

好吧,看来在 Apple 的 Utility App's 模板中,他们忽略了 [UIViewController][1] 的文档所说的内容,实际上不遗余力地调用 dismissModalViewControllerAnimated:将模态视图推送到屏幕上的 UIViewController

您的情况的基本思想是

  1. AddShowViewControllerDelegate 定义一个协议,
  2. 使 ShowListViewController 实现此协议,
  3. 在委托上调用一个方法,要求它关闭模态视图控制器

。示例只需使用 Utility 模板创建一个新项目,然后查看 FlipsideViewControllerMainViewController 的源代码

下面是一个适合您需求的示例:

AddShowViewController.h

@class AddShowViewController;

@protocol AddShowViewControllerDelegate
- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller;
@end

@interface AddShowViewController : UIViewController

@property (nonatomic, assign) id <AddShowViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

@end

AddShowViewController.m

- (IBAction)done:(id)sender
{
    [self.delegate addShowViewControllerDidFinish:self];
}

ShowListViewController.h

@interface ShowListViewController : UIViewController <AddShowViewControllerDelegate>
{   
    ...
}

ShowListViewController.m

- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
    [self populateTableData];
}

OK so it appears that in Apple's template for Utility App's they ignore what the docs for [UIViewController][1] say and actually go out of their way to call dismissModalViewControllerAnimated: from the UIViewController that pushed the modal view onto screen.

The basic idea in your case will be

  1. Define a protocol for AddShowViewControllerDelegate
  2. Make ShowListViewController implement this protocol
  3. Call a method on the delegate to ask it to dimiss the modal view controller

For a full example just create a new project with Utility template and look at the source for FlipsideViewController and MainViewController

Here is an example adapted for your needs:

AddShowViewController.h

@class AddShowViewController;

@protocol AddShowViewControllerDelegate
- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller;
@end

@interface AddShowViewController : UIViewController

@property (nonatomic, assign) id <AddShowViewControllerDelegate> delegate;

- (IBAction)done:(id)sender;

@end

AddShowViewController.m

- (IBAction)done:(id)sender
{
    [self.delegate addShowViewControllerDidFinish:self];
}

ShowListViewController.h

@interface ShowListViewController : UIViewController <AddShowViewControllerDelegate>
{   
    ...
}

ShowListViewController.m

- (void)addShowViewControllerDidFinish:(AddShowViewController *)controller
{
    [self dismissModalViewControllerAnimated:YES];
    [self populateTableData];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文