我的视图控制器在被调用后正在丢失它的属性。所以BaseTransitionController有一个(assign)int值,随着人们在应用程序中移动而改变。我想在另一个视图控制器中获取该int值,所以我在这个中初始化它(ViewController B)。 Self.indexSelectedLogin是ViewController B的一个属性。但是,当它们的值应为1-5时,rootController.indexSelected和self.indexSelectedLogin的值都为0。感谢
@interface BaseTransitionController : UIViewController
@property (assign) int indexSelected;
------------------------------------------------------------------
View Controller B
BaseTransitionController *rootController = [[BaseTransitionController alloc] init];
self.indexSelectedLogin = rootController.indexSelected;
答案 0 :(得分:0)
为此你必须保留旧的int值并传递给新的int变量,如下所示: -
@interface BaseTransitionController : UIViewController
@property (assign) int indexSelected;
//Assuming here indexSelected =5;
------------------------------------------------------------------
View Controller B
@property (nonatomic,strong) BaseTransitionController *rootController
//Now in this before alloc init just check the instance of BaseTransitionController
//if instance exist then you will get the retain value
self.indexSelectedLogin = self.rootController.indexSelected;
if(!self.rootController)
{
self.rootController = [[BaseTransitionController alloc] init];
}
因此,您可以相应地保存该值并在类中设置相同的值。