从子UIViewControllers检索UINavigationController属性

时间:2012-10-03 17:07:40

标签: objective-c properties uinavigationcontroller subclass

我创建了一个名为UINavigationController的{​​{1}}子类,它跟踪用户当前所处的级别。

它有一个名为CustomNavigationController的属性,类型为currentLevel

NSString

我可以使用以下内容从子视图控制器中检索属性:

// CustomNavigationController.h
#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController{
    NSString *_currentLevel;
}    
@property (nonatomic, retain) NSString *currentLevel;
@end

但是,currentLevel始终返回[(CustomNavigationController *)self.navigationController currentLevel];

我在视图控制器中引用了一个setter方法,它增加了它:

(null)

但是,当新的视图控制器被压入堆栈或从堆栈中弹出时,[(CustomNavigationController *)self.navigationController setCurrentLevel:@"Level 5"]; NSLog(@"%@",[(CustomNavigationController *)self.navigationController currentLevel]); //returns Level 5 方法中的原始行返回viewDidLoad

我的(null)中会包含特定类型的ViewController。此视图控制器取决于知道它的级别。我有逻辑来返回特定结果,具体取决于用户当前在CustomNavigationController上查看的级别。

0 个答案:

没有答案