The cocoa behavior is:

Exclusive bindings are impossible in IB
Possible in code (tested with segmented control and selectedIndex & selectedTag) but then you get unexpected behavior. A segment can be selected after a click and then
changes to another segment.
After this commit, extra exclusive bindings are just ignored and we warn about it.
This commit is contained in:
cacaodev
2014-09-12 22:33:50 +02:00
parent 68b193a782
commit a2755221d0
2 changed files with 9 additions and 7 deletions
+1 -2
View File
@@ -454,8 +454,7 @@ var CPBindingOperationAnd = 0,
if (![CPBinder isBindingAllowed:aBinding forObject:self])
{
[CPException raise:CPGenericException
reason:@"Cannot bind " + aBinding + " because a binding with the same functionality is already in use."];
CPLog.warn([self description] + " : cannot bind " + aBinding + " because another binding with the same functionality is already in use.");
return;
}
//if (![[self exposedBindings] containsObject:aBinding])
+8 -5
View File
@@ -342,7 +342,7 @@
[self assert:@"brie" equals:[control2 objectValue] message:@"control2 objectValue is wrong"];
}
- (void)testExclusiveBindingsThrowsException
- (void)testExclusiveBindings
{
var segmented = [[CPSegmentedControl alloc] initWithFrame:CGRectMakeZero()];
[segmented setSegmentCount:3];
@@ -351,10 +351,13 @@
[segmented bind:CPSelectedIndexBinding toObject:model withKeyPath:@"cheese" options:nil];
[self assertThrows:function()
{
[segmented bind:CPSelectedTagBinding toObject:model withKeyPath:@"cheese" options:nil];
}];
// Try to bind another binding (mutually exclusive) to the same value.
[segmented bind:CPSelectedTagBinding toObject:model withKeyPath:@"cheese" options:nil];
[self assertNotNull:[segmented infoForBinding:CPSelectedIndexBinding]];
// Check that the source is not binded with the CPSelectedTagBinding
[self assertNull:[segmented infoForBinding:CPSelectedTagBinding]];
}
@end