Reputation: 71
When I try to run this code, I get an error saying that:
Incompatible integer to pointer conversion sending 'BOOL' (aka 'signed char') to parameter of type 'BOOL *' (aka 'signed char *')
on the line
[self.MMdelegate addItemViewControllerMM:self didCheck1: checked1 didCheck2: checked2 ];
MatchModeViewController.h
@class MatchModeViewController;
@protocol MatchModeViewControllerDelegate <NSObject>
- (void)addItemViewControllerMM:(MatchModeViewController *)MMcontroller didCheck1:(BOOL *)MMbool didCheck2:(BOOL *)MMbool2;
@end
@interface MatchModeViewController : UIViewController {
BOOL checked1;
BOOL checked2;
}
@property BOOL checked1;
@property BOOL checked2;
@property (weak, nonatomic) IBOutlet UIButton *checkBoxButton1;
@property (weak, nonatomic) IBOutlet UIButton *checkBoxButton2;
- (IBAction)checkButton1:(id)sender;
- (IBAction)checkButton2:(id)sender;
@end
MatchModeViewController.m
@synthesize checkBoxButton1;
@synthesize checkBoxButton2;
@synthesize checked2;
@synthesize checked1;
- (void)viewDidLoad {
[super viewDidLoad];
checked1 = NO;
checked2 = NO;
[checkBoxButton1 setImage:[UIImage imageNamed:@"CheckBox.png"] forState: UIControlStateNormal];
[checkBoxButton2 setImage:[UIImage imageNamed:@"CheckBox.png"] forState: UIControlStateNormal];
UIBarButtonItem *saveButtonMM = [[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveButtonMMPressed)];
self.navigationItem.rightBarButtonItem = saveButtonMM;
}
-(instancetype) init {
if (self = [super init]) {
}
return self;
}
- (void) saveButtonMMPressed {
if([self.MMdelegate respondsToSelector:@selector(addItemViewControllerMM:didCheck1:didCheck2:)]){
[self.MMdelegate addItemViewControllerMM:self didCheck1: checked1 didCheck2: checked2 ];
[[NSNotificationCenter defaultCenter]postNotificationName:@"MMNOTIFICATIONNAME" object:nil];
}
[self.navigationController popViewControllerAnimated:YES ];
[self performSelector:@selector(saveButtonMMPressed) withObject:nil afterDelay:0.25];
}
I am a beginner at xcode and any help would be greatly appreciated.
Upvotes: 1
Views: 157
Reputation: 2381
This is more of a C question. Looking at your method:
- (void)addItemViewControllerMM:(MatchModeViewController *)MMcontroller didCheck1:(BOOL *)MMbool didCheck2:(BOOL *)MMbool2;
it seems that MMbool
and MMbool2
are supposed to be output parameters, and you need to pass them by reference.
So, instead of calling like this: [self.MMdelegate addItemViewControllerMM:self didCheck1:checked1 didCheck2: checked2];
you should call it like this: [self.MMdelegate addItemViewControllerMM:self didCheck1:&checked1 didCheck2:&checked2 ];
Placing that &
before checked1
send the reference of the variable instead of the value, so whatever change you make to checked1
within the method will be visible in the function that called it.
LE:
Or maybe you don't need to pass them by reference. In that case you should redefine the protocol method to - (void)addItemViewControllerMM:(MatchModeViewController *)MMcontroller didCheck1:(BOOL)MMbool didCheck2:(BOOL)MMbool2;
(without the * which makes the BOOLs pointers)
Upvotes: 1
Reputation: 318934
You are incorrectly defining your protocol method with pointers to BOOL
. You want:
@protocol MatchModeViewControllerDelegate <NSObject>
- (void)addItemViewControllerMM:(MatchModeViewController *)MMcontroller didCheck1:(BOOL)MMbool didCheck2:(BOOL)MMbool2;
@end
Also update any implementation of this method to get rid of the pointers.
Upvotes: 2