简体   繁体   English

在视图控制器和标签栏控制器之间传递数据

[英]Passing data between view controllers and tab bar controller

i've got this method in my dashBoardViewController.m 我在dashBoardViewController.m中有此方法

   - (void)demoSetup
    {
        self.tabBar.tintColor = [UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1]; // set the tab bar tint color to something cool.

        self.delegate = self;   // Just to demo that delegate methods are being called.


    }


    #pragma UITabBarController Delegate
    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
    {
        NSLog(@"UITabBarDelegate: shouldSelectViewController...");
        return YES;
    }

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
        NSLog(@"UITabBarDelegate: didSelectViewController...");
    }

    - (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers
    {
        NSLog(@"UITabBarDelegate: willBeginCustomizingViewControllers...");
    }

    - (void)tabBarController:(UITabBarController *)tabBarController willEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
    {
        NSLog(@"UITabBarDelegate: willEndCustomizingViewControllers...");
    }

    - (void)tabBarController:(UITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
    {
        NSLog(@"UITabBarDelegate: didEndCustomizingViewControllers...");
    }

i've got 4 linked on it, and a view with Facebook login i need to pass from the view that contains Facebook login 2 datas (FBID, FBUSER) to my dashBoardViewController and from it pass the same data to all of my tabs, is it possible? 我有4个链接,一个带有Facebook登录名的视图我需要从包含Facebook登录名2个数据(FBID,FBUSER)的视图传递到我的dashBoardViewController,并从该视图将相同的数据传递给我的所有标签,有可能吗

this is the dashBoardViewController.h 这是dashBoardViewController.h

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import "BFPaperTabBarController.h"

@interface dashBoardViewController : BFPaperTabBarController <UITabBarControllerDelegate,FBLoginViewDelegate> 

@property (weak, nonatomic) IBOutlet FBLoginView *loginButton;

@property (retain, nonatomic) NSString *id;

@property (retain, nonatomic) NSString *first_name;


@end

Create FBID, FBUSER properties in the required viewcontroller classes.Then write a method to create a shared instance of the view controller in the view controller class 在所需的viewcontroller类中创建FBID,FBUSER属性,然后在view controller类中编写一个方法以创建View Controller的共享实例

+ (instancetype)sharedInstance {
static MyViewController *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    instance = [[self alloc] init];
});
return instance;

} }

This method will return a shared instance of MyViewController class. 此方法将返回MyViewController类的共享实例。 This is a static object. 这是一个静态对象。

MyViewController *myViewController = [MyViewController sharedInstance];

set your properties as myViewController.fbid = yourvalue or myViewController.first_name = yourvalue 将您的属性设置为myViewController.fbid = yourvalue或myViewController.first_name = yourvalue

You have to implement this shared instance method in all of your view controllers. 您必须在所有视图控制器中实现此共享实例方法。 So that you can create static objects and set a not static property as static 这样您就可以创建静态对象并将非静态属性设置为static

Here's my understanding of the view controller setup. 这是我对视图控制器设置的理解。 ----- FaceBook Login VC | ----- FaceBook登录VC | --> TabBarController --|----- VC1 | -> TabBarController-| ----- VC1 | |------VC2 | | ------ VC2 | ------VC3 ------ VC3

If the diagram looks right and you are trying to pass data between FaceBookLogin and VC -1, V-2 and VC -3. 如果该图看起来正确,并且您正在尝试在FaceBookLogin和VC -1,V-2和VC -3之间传递数据。

You can do this by creating a subclass of TabBar Controller. 您可以通过创建TabBar控制器的子类来实现。 In your subclass declare two properties for FBID and FBUSER. 在子类中,声明FBID和FBUSER的两个属性。 If the use successfully logs in using "FaceBook Login" page, then set these properties in the custom tabBar controller. 如果使用“ FaceBook登录”页面成功登录,则在自定义tabBar控制器中设置这些属性。

You can now access these properties from any VC that is part of the tabbar controller. 现在,您可以从作为选项卡控制器一部分的任何VC中访问这些属性。

Let me know if you need to see some code or need more detailed explanation. 让我知道您是否需要查看一些代码或需要更详细的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在选项卡控制器中的两个视图控制器之间传递数据 - Passing data between two view controllers in a tab controller 如何在带有Tab Bar Controller的View Controller之间传输浮点值? - How to transfer a float value between View Controllers with Tab Bar Controller? 使用自定义选项卡栏控制器类在两个视图控制器之间传递数据 - Pass Data Between Two View Controllers Using a Custom Tab Bar Controller Class 在 Swift 中使用 NSNotificationCenter 在 Tab Bar Controllers 之间传递数据 - Passing data between Tab Bar Controllers with NSNotificationCenter in Swift 在视图控制器之间传递数据:从uitableview到详细信息视图控制器 - Passing Data between View Controllers : from uitableview to a details view controller 可以在视图控制器之间传递数据,但选项卡栏消失 - Can pass data between View Controllers but Tab bar disappears 将数据从视图控制器传递到iOS中的标签栏控制器 - Passing data from view controller to tab bar controller in iOS 将模型数据作为iOS中的明细控制器传递到标签栏视图控制器 - Passing model data to tab bar view controller as a detail controller in iOS 替换选项卡栏控制器的视图控制器之一 - Replace one of the view controllers of tab bar controller 后续视图控制器上缺少标签栏控制器 - Tab Bar Controller missing on subsequent View Controllers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM