Episode 10 - Bindings and NSController (Cont).
Posted 12/25/2006 - 15:40 by cocoacast
This Podcast is the second part of the two podcasts that will cover Key-Value Coding (KVC) and Cocoa bindings. We will start working on the RaiseMan application and take a look at how bindings are set in Interface Builder. We will cover the remainder of the chapter, including Soring, Key Paths, and solutions to challenges.
Here are the show notes for this Episode: Show Notes
View the Podcast
Show Notes:
Bindings and NSControler (cont.)
Episode 10
Introduction to Cocoa Bindings and more on KVC
Chapter 6 - Bindings and NSController (cont.)
Bindings and NSControler (cont.)
Episode 10
Introduction to Cocoa Bindings and more on KVC
Chapter 6 - Bindings and NSController (cont.)
Podcast Announcements
• New Recording Format
• Tell us what You Think - Forum + eMail
Podcast Announcements
• New Recording Format
• Tell us what You Think - Forum + eMail
Recap of the Last Episode
Summary of the Episode 8
Recap of the Last Episode
Summary of the Episode 8
Summary of Episode 8
• Solution to Challenge from Chapter 5
• Chapter 6 Bindings and NSController
• NSController
• Key-Value Coding
• Bindings
• First Version of RaiseMan application
Summary of Episode 8
• Solution to Challenge from Chapter 5
• Chapter 6 Bindings and NSController
• NSController
• Key-Value Coding
• Bindings
• First Version of RaiseMan application
In this Episode
• Finish Chapter 6
• KVC and nil
• Sorting
• Sorting Without NSArrayController
• Key Paths
• Challenges and Solutions (if time permits)
In this Episode
• Finish Chapter 6
• KVC and nil
• Sorting
• Sorting Without NSArrayController
• Key Paths
• Challenges and Solutions (if time permits)
KVC and nil
Dealing with issues when setting nil values on non-objects
KVC and nil
Dealing with issues when setting nil values on non-objects
• Objects can have nil values
• Non-objects cannot contain nil
• NSObject defines - (void)setNilValueForKey:(NSString *)s
Key-Value Coding and nil
- (void)setNilValueForKey:(NSString *)key{
if ([key isEqual:@”expectedRaise”]) {
[self setExpectedRaise:0.0];
} else {
[super setValueForKey:key];
}
}
• Objects can have nil values
• Non-objects cannot contain nil
• NSObject defines - (void)setNilValueForKey:(NSString *)s
Key-Value Coding and nil
- (void)setNilValueForKey:(NSString *)key{
if ([key isEqual:@”expectedRaise”]) {
[self setExpectedRaise:0.0];
} else {
[super setValueForKey:key];
}
}
Demo
Sorting with NSArrayController
Demo
Sorting with NSArrayController
Sorting Without NSArrayController
Adding sorting to your table programatically
Sorting Without NSArrayController
Adding sorting to your table programatically
• Info about columns in table is packed into array of NSSortDescriptor objects
• To sort NSMutableArray call:
• - (void)sortUsingDescriptors:(NSArray *)sortDescriptors
Sorting without NSArrayController
- (void)tableView:(NSTableView *)tableViewsortDescriptorsDidChange:(NSArray *)oldDescriptors{
NSArray *newDescriptors = [tableView sortDescriptors];
[myArray sortUsingDescriptors:newDescriptors];
[tableView reloadData];
}
• Info about columns in table is packed into array of NSSortDescriptor objects
• To sort NSMutableArray call:
• - (void)sortUsingDescriptors:(NSArray *)sortDescriptors
Sorting without NSArrayController
- (void)tableView:(NSTableView *)tableViewsortDescriptorsDidChange:(NSArray *)oldDescriptors{
NSArray *newDescriptors = [tableView sortDescriptors];
[myArray sortUsingDescriptors:newDescriptors];
[tableView reloadData];
}
A way of traversing items in object network
Key Paths
A way of traversing items in object network
Key Paths
• Objects that contain other objects form a network
• - (id)valueForKeyPath:(NSString *)path
• There are special operators:
Key Path
@avg @count @max @min @sum
Example:
[textFiled bind:@”value”
toObject:personControllerwithKeyPath:@”arrangedObjects.@avg.expectedRaise”
objects:nil];
• Objects that contain other objects form a network
• - (id)valueForKeyPath:(NSString *)path
• There are special operators:
Key Path
@avg @count @max @min @sum
Example:
[textFiled bind:@”value”
toObject:personControllerwithKeyPath:@”arrangedObjects.@avg.expectedRaise”
objects:nil];
Challenges
• Challenge 1
• Sort based on number of characters in personName
• Challenge 2
• RaiseMan without bindings
Challenges
• Challenge 1
• Sort based on number of characters in personName
• Challenge 2
• RaiseMan without bindings
Sorting based on number of characters in personName
Challenge 1 solution
Sorting based on number of characters in personName
Challenge 1 solution
RaiseMan without bindings - Part of a Special Podcast on Bindings
Challenge 2 solution
RaiseMan without bindings - Part of a Special Podcast on Bindings
Challenge 2 solution
Summary
• Finished Chapter 6
• KVC and nil
• Sorting
• Sorting Without NSArrayController
• Key Path
• Challenges and Solutions
Summary
• Finished Chapter 6
• KVC and nil
• Sorting
• Sorting Without NSArrayController
• Key Path
• Challenges and Solutions
Next Time
• Advanced Cocoa Bindings
• RaiseMan without Bindings - Challenge 2 from Chapter 6
• Expanded RaiseMan
• Other Bindings-related topics
Next Time
• Advanced Cocoa Bindings
• RaiseMan without Bindings - Challenge 2 from Chapter 6
• Expanded RaiseMan
• Other Bindings-related topics
The Best Code is the Code...
you do not have to Write
The Best Code is the Code...
you do not have to Write





23 weeks 3 days ago
23 weeks 4 days ago
23 weeks 5 days ago
23 weeks 5 days ago
23 weeks 6 days ago
23 weeks 6 days ago
23 weeks 6 days ago
23 weeks 6 days ago
23 weeks 6 days ago
23 weeks 6 days ago