如何从自定义类访问变量?

时间:2014-05-05 08:51:14

标签: ios

以下是故事板中的内容:

enter image description here

CustomTabBarController.h:

#import <UIKit/UIKit.h>

@interface CustomTabBarController : UITabBarController<UITabBarDelegate>
@property NSUInteger tabIndex;
@property NSUInteger pageIndex;
@end

我在CustomTabBarController中存储了变量如何在RootViewController中访问它们?

2 个答案:

答案 0 :(得分:0)

前提条件: <{1}}界面(CustomTabBarController)中的属性需要公开

CustomTabBarController.h

您可以通过 tabBarController中的任何控制器访问该媒体资源:

@interface CustomTabBarController

@property (strong, nonatomic) Class *object;

@end

答案 1 :(得分:0)

您可以从标签栏控制器的 viewControllers 属性访问根视图控制器。您需要将其强制转换为适当的类。例如

static NSString *const TabIdentifier = TAB_IDENTIFIER;
UITabBarController *tabBarController=[storyboard instantiateViewControllerWithIdentifier:TabIdentifier];
[(ViewController *)[tabBarController.viewControllers objectAtIndex:0] setData:mdata];
相关问题