2014-04-14 48 views
0

我正在使用iBeacons演示应用程序。在这个时候,当我想在第二个视图控制器中显示信标数据的详细视图时,我已经有了在第一个视图控制器中工作的信标的范围。我听到关于信标变化的可听反馈,这意味着检测最近信标的循环仍然在视图控制器1中运行...但是如何从我的第二个视图控制器中的视图控制器1获取更新?ibeacon不等oin背景输出到第二视图控制器

我试着在segue中传递它们,但后来它是静态的NSString数据,任何人都可以帮助我如何获得第二个视图控制器中的“活”数据?

回答

0

如果您想在多个ViewController中处理远程iBeacon数据,您可以在AppDelegate中设置范围,然后从那里调用每个ViewController上的公共方法。主要的didRangeBeacons:inRegion:在你的AppDelegate中,如果ViewController被激活,可以调用每个ViewController的自定义方法。

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { 
    if (self.firstViewController != Nil) { 
     [self.firstViewController handleBeacons: beacons]; 
    } 
    if (self.secondViewController != Nil) { 
     [self.secondViewController handleBeacons: beacons]; 
    } 
} 

为了做到这一点如上,你必须保持你的AppDelegate中为每个视图控制器属性:

@interface MyAppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) FirstViewController *firstViewController; 
@property (strong, nonatomic) SecondViewController *secondViewController; 

@end 

您可以从每个视图控制器填充它们是这样的:

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    MyAppDelegate *appDelegate = (MyAppDelegate) [[UIApplication sharedApplication] delegate]; 
    appDelegate.firstViewController = self; 
} 
相关问题