-3

Hi I have a tabbed view application with 4 different tabs! I want my third tab (the view controller is thirdViewController) to monitor and range the estimote beacons around. The code in the app delegate that gives the above error is commented one in the method given below:

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    NSString *message = @"";

    ThirdViewController *viewController = (ThirdViewController*)self.window.rootViewController;

    viewController.beacons = beacons; //this line of code gives the above error
    [viewController.tableView reloadData];
}
mbm29414
  • 11,558
  • 6
  • 56
  • 87
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Jan 30 '15 at 17:44
  • Of course, since you did not give the complete error message you make it much harder for anyone to help you. – Hot Licks Jan 30 '15 at 17:44

1 Answers1

1

You say your app is a tabbed view application.

If that's the case, then self.window.rootViewController in your AppDelegate will return a UITabBarViewController.

You can probably fix your error with this code:

- (void)locationManager:(CLLocationManager *)manager 
        didRangeBeacons:(NSArray *)beacons 
               inRegion:(CLBeaconRegion *)region {

    NSString *message = @"";
    UITabBarViewController *tabVc = (UITabBarViewController *)self.window.rootViewController;
    ThirdViewController *viewController = (ThirdViewController*)tabVc.viewControllers[2];

    viewController.beacons = beacons;above error
    [viewController.tableView reloadData];
}
mbm29414
  • 11,558
  • 6
  • 56
  • 87
  • Thanks a lot for the reply. I will certainly try this one as well. I fixed the problem using the singleton class. But this one seems interesting too – Fahim Zafari Feb 03 '15 at 19:01