
我有一个基本视图(视图1),我可以在其中选择tablevIEw中的项目.在项目“页面”(视图2)上,我可以选择编辑该项目,触发模态视图(视图3).
在此模态视图中,我可以选择删除此项目.如果用户按下该按钮并确认他们要删除该项目,我想将该应用程序发送回视图1 ..
我已经尝试了很多不同的东西(popToVIEwController,pushVIEwController,dismissVIEwController等等),但我无法得到任何工作.如果我关闭模态,则视图2不会关闭.有时甚至模态也不会消失.基本视图是一个UItableVIEwController,另外两个是UIVIEwControllers,我正在使用storyboard.
解决方法 您有几个选项可以使用NSNotificationCenter或使用 delegate模式.NSNotificationCenter易于使用,但也很棘手.
要使用通知中心,您需要将观察者添加到视图控制器类.当您关闭模态视图控制器时,您通知视图2视图3现在被解除,vIEw2可以解雇自己…..
所以基本上当你通知中心时,无论通知它运行方法等….
让我们在第3点说你要解雇你的观点.
在vIEw3 .m
-(IBAction)yourMethodHere{ //dissmiss vIEw [self.navigationController dismissModalVIEwControllerAnimated:YES]; // or [self dismissModalVIEwControllerAnimated:YES]; whateever works for you //send notification to parent controller and start chain reaction of poPing vIEws [[NSNotificationCenter defaultCenter] postNotificationname:@"goToVIEw2" object:nil];} 在视图2中. H
// For name of notificationextern Nsstring * const NOTIF_LoggingOut_Settings;
在视图2.在#i进入之后的@implementation之前
Nsstring * const NOTIF_LoggingOut_Settings = @"goToVIEw2"; @implementation -(voID)vIEwDIDAppear:(BOol)animated{ // Register observer to be called when logging out [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(loggingOutSettings:) name:NOTIF_LoggingOut_Settings object:nil]; } /*--------------------------------------------------------------------------- * Notifications of 2 vIEw *--------------------------------------------------------------------------*/ - (voID)loggingOutSettings:(NSNotification *)notif { NSLog(@"Received Notification - Settings Pop Over popped"); [self.navigationController popVIEwControllerAnimated:NO];// change this if you do not have navigation controller //call another notification to go to vIEw 1 [[NSNotificationCenter defaultCenter] postNotificationname:@"goToFirstVIEw" object:nil]; } 在第一个视图中添加另一个观察者
在你的vIEw1.h
extern Nsstring * const NOTIF_FirstVIEw;
在#impount之后的@implementation之前的m
Nsstring * const NOTIF_FirstVIEw = @“goToFirstVIEw”;
@implementation-(voID)vIEwDIDAppear:(BOol)animated{ // Register observer to be called when logging out [[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(doYourThing:) name:NOTIF_FirstVIEw object:nil];}/*--------------------------------------------------------------------------- * Notifications of 1 vIEw *--------------------------------------------------------------------------*/- (voID)ldoYourThing:(NSNotification *)notif{ // do your thing} 总结 以上是内存溢出为你收集整理的IOS:移回两个视图全部内容,希望文章能够帮你解决IOS:移回两个视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)