委托操作永远不会被调用
当我的模式视图被关闭时,当我尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您缺少(或者尚未发布)为
loginDelegate
赋值的部分。您提到综合它,但这只创建访问器方法,它不设置值。在代码中的某个地方,您需要这样的语句:
或者,无论对象创建此视图控制器,都会在创建它之后但在呈现它之前将其自身或另一个对象设置为委托:
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:
Or, whatever object creates this view controller would set itself or another object as the delegate after creating it but before presenting it: