Simple TextView not updating view
Simple TextView not updating view
- Subject: Simple TextView not updating view
- From: Johnny Lundy <email@hidden>
- Date: Sun, 13 Apr 2008 11:36:22 -0400
First, thanks to Quincey Morris for clarifying the
mutableArrayValueForKey issue to get proper KVO on a mutableArray when
deleting objects from the Model. It works just fine. I think that will
also allow me to get my addObject button to work.
I am tackling these issues one at a time. My goal here is just porting
an existing AppleScript Studio app, which works fine, to use Cocoa
Bindings, aiming for 100% "no-glue-code". Just to learn.
Next issue is that I have a simple NSTextView, plain text. It displays
the current votes for each player suitable for copying and pasting
into a forum thread post.
My app has one single class, VoterController: NSObject, which has all
of the instance variables and instance methods. I should probably
break it up, but for clarity it seems to help.
The Model is an NSMutableString
@property (readwrite, copy) NSMutableString *postText;
@synthesize postText;
The View is an NSTextView in IB, class left as the default NSTextView.
Its bindings are:
Bind To: textViewController
Controller Key: selection
Model Key Path: postText
The Controller is textViewController, an NSObjectController. Its
bindings are
Bind To: postText (an NSObject in IB that has class VoterController
Controller Key: blank
Model Key Path: postText (the Model Object, represented in IB by the
above "postText" NSObject in IB)
The Model Object in IB is, as stated, an NSObject with class
VoterController and name postText.
So the connections are
NSMutableString * postText instance variable ->postText NSObject in IB-
>textViewController in IB ->NSTextView in IB.
Here is the method my code calls to modify the postText mutableString
when there is a vote or an unvote. It summarizes all the votes for
players in playerArray. threshold is a function that returns an integer.
- (NSMutableString *) postText
{
postText = [NSMutableString stringWithFormat: @"<b>Official Vote
Count:\nNeeded To Lynch:%d</b>\n", [self threshold]];
for (NSMutableDictionary *thePlayer in playerArray)
{
int currVote = [[thePlayer valueForKey:@"voteCount"]intValue];
if (currVote > 0)
{
postText = [[postText stringByAppendingFormat:@"%@ - %@ - %@ (L-%d)
\n",
[thePlayer valueForKey:@"playerName"],
[thePlayer valueForKey:@"voteCount"],
[thePlayer valueForKey:@"votersForString"],
[self threshold] - currVote] mutableCopy];
}
}
[self saveToFile];
return postText;
}
The postText mutableString gets correctly modified, but does not
change in the TextView.
I'm pretty sure I have the bindings wrong. Appreciate any help.
Cheers,
Johnny
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden