The situation:
I've got three views named LogInView, CategoryRegistrationView, and BlueToothCheckerView. Both LogInView and CategoryRegistrationView can segue to BlueToothCheckerView.
BlueToothCheckerView itself can segue into two different views, depending on a string set by LogInView or CategoryRegistrationView.
LogInView does this just fine. A user can log in from LogInView, check if his Bluetooth connection is on in BlueToothCheckerView, and is then redirected to a view he won't see if he otherwise came in from CategoryRegistrationView.
CategoryRegistrationView has problems.
The Problem:
On click of the button to take me to BlueToothView, this error appears:
[BlueToothCheckerViewController setFromSegue:]: unrecognized selector sent to instance 0x7f8c935a4f80
A lot of posts online indicated that it's because BlueToothCheckerView is not set as the Custom Class for xib BlueToothView, but it is.
The Code (We'll be focusing on CategoryRegistrationView and BlueToothCheckerView to keep things short):
CategoryRegistrationViewController.h
- Problem segment:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
NSLog(@"Segue Identifier: %@", [segue identifier]);
if ([[segue identifier] isEqualToString:@"CategoryRegistrationToBlueToothCheckerSegue"]) {
BlueToothCheckerView *btcv = [segue destinationViewController];
btcv.fromSegue = @"CategoryRegistrationToBlueToothCheckerSegue"; // <-- Error here
NSLog(@"Something wrong here");
}
}
Note: LogInViewController has the exact same code, with btvc.fromSegue set to "LoginToBlueToothCheckerSegue" instead.
BlueToothCheckerView.h
#import <UIKit/UIKit.h>
@protocol BlueToothCheckerViewDelegate <NSObject>
@required
- (void)skipPressed:(id)sender;
@end
@interface BlueToothCheckerView : UIView
@property (weak, nonatomic) id<BlueToothCheckerViewDelegate> delegate;
@property (weak, nonatomic) IBOutlet UIButton *SkipButton;
@property (nonatomic) NSString* fromSegue;
- (IBAction)skipPressed:(id)sender;
@end
BlueToothCheckerViewController.h
#import "BaseUIViewController.h"
#import "BlueToothCheckerView.h"
#import "Constants.h"
#import <CoreBluetooth/CoreBluetooth.h>
@interface BlueToothCheckerViewController : BaseUIViewController <BlueToothCheckerViewDelegate,CBCentralManagerDelegate>
@property (weak, nonatomic) BlueToothCheckerView *btcv;
@end
Both BlueToothCheckerView
and BlueToothCheckerViewController
at the very least show string fromSegue.
Here's a sample of how fromSegue is used, in BlueToothCheckerViewController.m
:
- (void)skipPressed:(id)sender {
NSLog(@"Bluetooth already on");
if ([self.btcv.fromSegue isEqual: @"LoginToBlueToothCheckerSegue"]){
[self performSegueWithIdentifier:@"BlueToothCheckerToDashboardSegue" sender:self];
}
else if ([self.btcv.fromSegue isEqual: @"CategoryRegistrationToBlueToothCheckerSegue"]){
[self performSegueWithIdentifier:@"BlueToothCheckerToWalkthroughSegue" sender:self];
}
}
What I Tried:
I tried deleting the segue in question, and re-adding it. It didn't much. I also commented out the line btcv.fromSegue = @"CategoryRegistrationToBlueToothCheckerSegue";
, and confirmed the program ran fine without it.
I also tried adding a cast to BlueToothCheckerController. Didn't work either.
In light of this answer, I also checked my Build Phases. Here's what it looks like, if it matters.
Any thoughts, please?