0

所以我在我的第一个 iPhone 应用程序上。我其实很深入。我已经从许多错误中吸取了教训,但我觉得我犯了一个终极错误。我正在使用 segues 导航到不同的视图。我深入了解了大约 5 个 segue 视图,我意识到这会导致大量分配的内存。换句话说,视图 A 调用视图 B,B 进入 C,C 进入 D,等等。据我了解,当我到达 DI 时,现在已经打开了 ABC 和 D 的实例,这听起来不太好。例如,我正在使用代表,如下所示:

只是我在整个应用程序中所做的一个示例:

第一视角:

@interface FirstViewController : UIViewController<SecondViewControllerDelegate>

@end

第二种观点:

@class SecondViewController;

@protocol SecondReviewOrderViewControllerDelegate <NSObject>

 - (void)secondViewControllerDidCancel:(SecondViewController *)controller;

@end

@interface SecondViewController : UIViewController<ThirdViewControllerDelegate>
  @property (strong, nonatomic) id <SecondViewControllerDelegate> delegate;
@end

第三视图:

@class 第三视图控制器;

@protocol ThirdReviewOrderViewControllerDelegate <NSObject>

 - (void)thirdViewControllerDidCancel:(ThirdViewController *)controller;

@end

@interface ThirdViewController : UIViewController<>
  @property (strong, nonatomic) id <ThirdViewControllerDelegate> delegate;
@end

依此类推到视图 4 和 5。

我的问题是,如果这似乎是错误的,那么导航视图并将数据从一个视图控制器传递到另一个视图控制器的正确方法是什么?感谢您的任何提示。

4

1 回答 1

4

据我了解,当我到达 DI 时,现在已经打开了 ABC 和 D 的实例,这听起来不太好

视图控制器本身是一个相当轻量级的对象,无论深入多少层(例如将五个视图控制器推入导航控制器堆栈)都没有问题。但是,您可能持有的内存和图像不是轻量级的,因此请务必实施didReceiveMemoryWarning并在到达时认真对待。

放弃大量保留内存占用的东西以响应的策略didReceiveMemoryWarning是将其保存到磁盘(如果它不能按需重新创建),然后在下次要求时使用延迟初始化将其读回它。

于 2013-05-07T02:07:09.420 回答