Reputation: 17
I had a class(dicecontroller) with an IBAction and that would trigger some IBOutlets, all was happy. I since found a better way to organize my code and put the IBAction in a different class(playercommand). playercomman calls a method in dicecontroller which has all the IBOutlets, except now none of the outlets display anything. I reconnected the outlets with the xib, even made new outlets, no form of IBOutlets seem to work. However NSLog works just fine and the array i'm passing it is being received fine.
I've had trouble with Xcode acting weird and crashing recently which was fixed by reinstalling Xcode, i did that again thinking this might be another glitch, but no love. I'm thinking this is some nuance of IB that i just don't know about
I also don't really know how to look this up, been trying to find something for hours. Help would be encouraging.
PlayerCommand.h
#import "DiceRoll.h"
#import "diceController.h"
@interface playerCommand : NSObject
- (IBAction)roll:(NSButton *)sender;
@end
Playercommand.m
#import "playerCommand.h"
@implementation playerCommand
- (IBAction)roll:(NSButton *)sender {
DiceRoll *currentTurn = [[DiceRoll alloc] init];
[currentTurn rolldice];
diceController *currentFields = [[diceController alloc] init];
[currentFields updatetockNameField:[currentTurn diceValuesArray]];
}
@end
dicecontroller.h
@interface diceController : NSObject
-(void)updatetockNameField: (NSArray*) diceValues;
@end
dicecontroller.m
#import "diceController.h"
// declaring private properties
@interface diceController()
@property (weak) IBOutlet NSTextField *ActionField;
@property (weak) IBOutlet NSTextField *QuantityField;
@end
@implementation diceController
-(void)updatetockNameField:(NSArray *) diceValues {
switch ([[diceValues objectAtIndex:2] integerValue]) {
case 0 ... 1:
[[self ActionField] setStringValue:@"Up"];
break;
case 2 ... 3:
[[self ActionField] setStringValue:@"Down"];
break;
case 4 ... 5:
[[self ActionField] setStringValue:@"Div"];
break;
default:
[[self ActionField] setStringValue:@"Err"];
break;
}
switch ([[diceValues objectAtIndex:2] integerValue]) {
case 0 ... 1:
[[self QuantityField] setIntegerValue:5];
break;
case 2 ... 3:
[[self QuantityField] setIntegerValue:10];
break;
case 4 ... 5:
[[self QuantityField] setIntegerValue:20];
break;
default:
[[self QuantityField] setStringValue:@"E"];
break;
}
} //end of updatetockNameField method
@end
Upvotes: 0
Views: 700
Reputation: 17143
The issue is here:
diceController *currentFields = [[diceController alloc] init];
This diceController
instance is a new instance (you create it in this line). This is not the same diceController
instance which you had already placed and configured in your nib.
If your playerCommand
instance needs a reference to your diceController
instance in the nib, then you can make an IBOutlet in playerCommand
and connect that to the diceController
instance in your nib.
BTW, playerCommand
and diceController
should be named PlayerCommand
and DiceController
, respectively.
Upvotes: 1