委托操作永远不会被调用

发布于 2024-12-11 21:18:08 字数 1226 浏览 0 评论 0原文

当我的模式视图被关闭时,当我尝试从 rootViewController 中的 UITableView 重新加载数据时,我在使用协议/委托时遇到了问题。

以下是我的模态视图 .h 文件中的一些代码:

@protocol LoginWebViewDelegate <NSObject>
     -(void) updateFromModalView;
@end

@interface myModalView : UIViewController{
    id<LoginWebViewDelegate> loginDelegate; 
    ..
}
@property (nonatomic, assign) id<LoginWebViewDelegate> loginDelegate;
..
-(IBAction)dismiss;
..

在我的 .m 文件中,我合成了 loginDelegate & 。我实施解雇行动&当我按下按钮时它就被激活了。

-(IBAction) dismiss
{
    NSLog(@"Button Pressed!");
    [loginDelegate updateFromModalView];
}

接下来,在 rootViewController 的界面中,我添加了 &这是我的实现中的操作:

-(void) updateFromModalView
{
    [modalView dismissModalViewControllerAnimated:YES];
    NSLog(@"Reloading Data");
    [dataController readPlist];
    [dataTable reloadData];
    [dataTable beginUpdates];
    [dataTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable endUpdates];
}

updateFromModalView 方法永远不会被调用。我想念什么?

I'm having trouble using Protocols/Delegates when I was trying to reload the data from a UITableView in my rootViewController when my modal view is dismissed.

Here is some code from my modal view .h file:

@protocol LoginWebViewDelegate <NSObject>
     -(void) updateFromModalView;
@end

@interface myModalView : UIViewController{
    id<LoginWebViewDelegate> loginDelegate; 
    ..
}
@property (nonatomic, assign) id<LoginWebViewDelegate> loginDelegate;
..
-(IBAction)dismiss;
..

In my .m file I synthesize the loginDelegate & I implement the dismiss action & it's been activated when I press the button.

-(IBAction) dismiss
{
    NSLog(@"Button Pressed!");
    [loginDelegate updateFromModalView];
}

Next in the inteface of my rootViewController I added <LoginWebViewDelegate> & here is the action in my implementation:

-(void) updateFromModalView
{
    [modalView dismissModalViewControllerAnimated:YES];
    NSLog(@"Reloading Data");
    [dataController readPlist];
    [dataTable reloadData];
    [dataTable beginUpdates];
    [dataTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:YES];
    [dataTable endUpdates];
}

The method updateFromModalView never gets called. What do I miss?

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

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

发布评论

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

评论(1

羁客 2024-12-18 21:18:08

您缺少(或者尚未发布)为 loginDelegate 赋值的部分。您提到综合它,但这只创建访问器方法,它不设置值。

在代码中的某个地方,您需要这样的语句:

self.loginDelegate = _something_;

或者,无论对象创建此视图控制器,都会在创建它之后但在呈现它之前将其自身或另一个对象设置为委托:

modalController = [[ModalController alloc] initWithNibName:@"ModalController];
modalController.loginDelegate = self;
[self presentModalViewController:modalController];

You are missing (or you haven't posted) the part where you assign a value to loginDelegate. You mention synthesising it but that only creates accessor methods, it doesn't set a value.

Somewhere in your code you need a statement like:

self.loginDelegate = _something_;

Or, whatever object creates this view controller would set itself or another object as the delegate after creating it but before presenting it:

modalController = [[ModalController alloc] initWithNibName:@"ModalController];
modalController.loginDelegate = self;
[self presentModalViewController:modalController];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文