Nope. No compiler warnings.
I took out the @synthesize and @property compiler directives and manually wrote the setter and getter for the array. The Model array is updated, but the View isn't.
Let me describe the connections
In IB, I have two TableViews and two NSArrayControllers. They are both bound to the same model object, playerArray. I need two identical TableViews because I need different selections in them to operate on in my code.
Bindings for the left TableView:
Bind To: voterController
Controller Key: arrangedObjects
Model Key Path: playerName (each element of playerArray is an NSMutableDictionary, and one of the keys in the dictionary is playerName.)
Bindings for the ArrayController "voterController":
Bind To: mainController
Controller Key: {blank}
Model Key Path: playerArray
This controller is specified to have a Class of NSArrayController. It will not let me set it to "VoterController." (see below)
mainController:
This is a simple NSObject with Class of VoterController
No Bindings. Not allowed with an NSObject I guess. I don't understand File's Owner, but my guess is that this is taking the place of whatever File's Owner does.
I coded the setter and getter for playerArray as per your kind example.
Now for the Xcode files
VoterController.h
#import <Cocoa/Cocoa.h>
#import "VoteeController.h"
@interface VoterController : NSObject {
NSMutableArray *playerArray, *roleNumsArray, *roleTemplate;
NSString *path, *tempString;
NSScanner *flavorScanner, *roleScanner;
NSURLRequest *request;
NSData *theC9FlavorData;
NSData *theRandomRolesData;
NSMutableString *postText, *voteString;
NSInteger theRoleInteger, C9Flavor, indexOfTheWhackedOne;
BOOL fileFlag;
}
@property (readonly) NSMutableString *postText;
//User actions
- (void) voteFor:(NSArray *)votee byVoters:(NSArray *)voters;
- (void) nightKill: (NSNumber *) theWhackedOne;
- (void) reset;
- (void) generateRoles;
- (void) deleteRoles;
//Internal functions
- (NSMutableArray *) playerArray;
- (void) setPlayerArray: (NSArray *) newPlayerArray;
- (NSString *) makeVoteStringFromVoters:aVoter;
- (BOOL) checkForTwilight:(NSMutableDictionary *)aPlayer;
- (void) unVote: (NSNumber *) aVoter;
- (int) threshold;
- (void) saveToFile;
- (NSMutableString *) postText;
@end
VoterController.m: (-nightKill: is where the Model deletion of an array element works but does not update the view)
#import "VoterController.h"
#import "VoteeController.h"
@implementation VoterController
- (id) init
{
if (self = [super init])
{
NSBundle *mafiaBundle = [NSBundle mainBundle];
path = [mafiaBundle pathForResource:@"com.jlsoftware.mafia.playerTable" ofType:@"plist"];
playerArray = [[NSMutableArray arrayWithContentsOfFile:path]mutableCopy];
roleTemplate = [NSMutableArray arrayWithObjects:
@"Townie", @"Townie", @"Townie", @"Townie",
@"Townie", @"Mafia Goon", @"Mafia Goon", nil];
}
return self;
}
- (NSMutableArray *) playerArray
{
return playerArray;
}
- (void) setPlayerArray: (NSArray *) newPlayerArray
{
[playerArray autorelease];
playerArray = [[NSMutableArray alloc] initWithArray: playerArray];
}
- (BOOL) checkForTwilight:(NSMutableDictionary *)aPlayer
{return ([[aPlayer valueForKey:@"voteCount"]intValue] >= [self threshold]);}
- (void) unVote:(NSNumber *) aVoter
{
NSLog(@"unVote:aVoter=%@", aVoter);
[self postText];
}
- (int) threshold
{ return ([playerArray count] / 2) + 1;}
- (NSString *) makeVoteStringFromVoters:aVotee
{
if ([aVotee valueForKey:@"voteCount"] == 0)
{return @"";}
else
{
voteString =
[[NSString stringWithFormat:
@"(%@)",[[[aVotee valueForKey:@"votersFor"]allValues]
componentsJoinedByString:@", "]] mutableCopy];
return voteString;
}
}
- (void) saveToFile
{fileFlag = [playerArray writeToFile:path atomically:NO];}
- (NSMutableString *) postText
{
postText = [NSMutableString stringWithFormat:
@"Official Vote Count: Needed To Lynch:%d ", [self threshold]];
for (NSMutableDictionary *thePlayer in playerArray)
{
int currVote = [[thePlayer valueForKey:@"voteCount"]intValue];
if (currVote > 0)
{
postText = [[postText stringByAppendingFormat:@"%@ - %@ - %@ (L-%d) ",
[thePlayer valueForKey:@"playerName"],
[thePlayer valueForKey:@"voteCount"],
[thePlayer valueForKey:@"votersForString"],
[self threshold] - currVote] mutableCopy];
}
}
[self saveToFile];
return postText;
}
- (void) reset
{
for (NSMutableDictionary *thePlayer in playerArray)
{
[thePlayer setValue:0 forKey:@"voteCount"];
[thePlayer setObject: @"" forKey:@"votersForString"];
[thePlayer setObject: @"" forKey:@"currentVotedPlayer"];
[thePlayer setObject: [NSMutableDictionary dictionaryWithCapacity:4] forKey:@"votersFor"];
}
[self postText];
}
- (void) nightKill:(NSNumber *) theWhackedOne
{
NSLog(@"theWhackedOne=%@",theWhackedOne);
[playerArray removeObjectAtIndex:[theWhackedOne integerValue]];
[self reset];
[self postText];
return;
}
- (void) addPlayer:thePlayerNameString
{
NSBeep();
return;
}
- (void) deleteRoles
{
NSBeep();
NSBeep();
NSBeep();
return;
}
@end