如何在之后调用viewDidLoad;
好的。 如果你有两个viewController,并且你从第一个到第二个做一个模态Segue,那么你用[self dismissModalViewControllerAnimated:YES]来解雇它。 它似乎没有回忆viewDidLoad。 我有一个主页面(viewController),然后是一个选项页面的sorting,我希望主页面更新,当你改变一个选项。 当我刚刚做了两个模态段(前进一个,后退一个),但是这似乎是非结构化的,并可能导致大型项目中的混乱代码。
我听说过推塞格斯。 他们还好吗?
谢谢。 我感谢任何帮助:)。
这是因为UIViewController已经加载到内存中了。 你可以使用viewDidAppear:。
或者,您可以使推送视图控制器成为推送视图控制器的委托,并在推送控制器正在退出屏幕时通知其更新。
后一种方法有利于不需要重新运行整个viewDidAppear:
例如,如果只更新一个表格行,为什么要重新渲染整个事物呢?
编辑:只为你,这里是使用代表的一个快速的例子:
#import <Foundation/Foundation.h> // this would be in your ModalView Controller's .h @class ModalView; @protocol ModalViewDelegate - (void)modalViewSaveButtonWasTapped:(ModalView *)modalView; @end @interface ModalView : NSObject @property (nonatomic, retain) id delegate; @end // this is in your ModalView Controller's .m @implementation ModalView @synthesize delegate; - (void)didTapSaveButton { NSLog(@"Saving data, alerting delegate, maybe"); if( self.delegate && [self.delegate respondsToSelector:@selector(modalViewSaveButtonWasTapped:)]) { NSLog(@"Indeed alerting delegate"); [self.delegate modalViewSaveButtonWasTapped:self]; } } @end // this would be your pushing View Controller's .h @interface ViewController : NSObject <ModalViewDelegate> - (void)prepareForSegue; @end; // this would be your pushing View Controller's .m @implementation ViewController - (void)prepareForSegue { ModalView *v = [[ModalView alloc] init]; // note we tell the pushed view that the pushing view is the delegate v.delegate = self; // push it // this would be called by the UI [v didTapSaveButton]; } - (void)modalViewSaveButtonWasTapped:(ModalView *)modalView { NSLog(@"In the delegate method"); } @end int main(int argc, char *argv[]) { @autoreleasepool { ViewController *v = [[ViewController alloc] init]; [v prepareForSegue]; } }
输出:
2012-08-30 10:55:42.061 Untitled[2239:707] Saving data, alerting delegate, maybe 2012-08-30 10:55:42.064 Untitled[2239:707] Indeed alerting delegate 2012-08-30 10:55:42.064 Untitled[2239:707] In the delegate method
在CodeRunner for OS X中运行了一个例子 ,我和它没有联系。
- iOS Swift:UIPageViewController – 以编程方式翻页
- iOS Geofence,监控开始时如何处理内部区域?
- iOS应用程序可以通过WiFi进行“无线configurationconfiguration”时使用蜂窝networking连接吗?
- 以编程方式从通知托盘中删除UILocalNotification
- 测距信标只适用于应用程序运行?
- 可以在导航栏中为UIBarButtonItem设置背景图像,但不能在底部工具栏中设置背景图像
- 如何在ios中为UITextView设置内容embedded
- 初始化对象
- UICollectionView中的最后一项不是alligned – Swift