OT: NSComboBox
Moderators: winston, another_commander, Cody
OT: NSComboBox
I know this is off-topic, but I'm hoping that one of you guys can point me in the right direction
anyway, I have a window with 3 NSComboBoxes. 2 of them work ok. But the third one uses a data source, and when I try to use it, I keep getting SIGABRT and EXC_BAD_ACCESS. what am I doing wrong?
anyway, I have a window with 3 NSComboBoxes. 2 of them work ok. But the third one uses a data source, and when I try to use it, I keep getting SIGABRT and EXC_BAD_ACCESS. what am I doing wrong?
MacBook pro, OSX 10.8.5, Xcode 5
-
- Quite Grand Sub-Admiral
- Posts: 6680
- Joined: Wed Feb 28, 2007 7:54 am
Not Oolite related, moved to Outworld.
Some more information will be needed, I believe. In cases like this, posting the code that crashes can result in more accurate responses and faster solutions. My guess would be a wild pointer which you think it refers to the source data, when it may be nil or invalid.
Some more information will be needed, I believe. In cases like this, posting the code that crashes can result in more accurate responses and faster solutions. My guess would be a wild pointer which you think it refers to the source data, when it may be nil or invalid.
i assume you mean the delegate methods. here they are.another_commander wrote:Not Oolite related, moved to Outworld.
Some more information will be needed, I believe. In cases like this, posting the code that crashes can result in more accurate responses and faster solutions. My guess would be a wild pointer which you think it refers to the source data, when it may be nil or invalid.
Code: Select all
-(NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
NSUInteger number = [symbols count];
return number;
}
-(id)comboBox:(NSComboBox *)sender objectValueForItemAtIndex:(NSInteger)index {
NSLog(@"%i", index);
NSString *response = [symbols objectAtIndex:(int)index];
return response;
}
well, at least i've found out why i get an exception: the index is out of bounds of the array. but the question is, WHY is the index out of bounds, and what can i do about it? i've tried out typecasts, but so far no luck. gonna keep trying...
MacBook pro, OSX 10.8.5, Xcode 5
While my area is more c++, this looks like the classicharry747 wrote:i assume you mean the delegate methods. here they are.another_commander wrote:Not Oolite related, moved to Outworld.
Some more information will be needed, I believe. In cases like this, posting the code that crashes can result in more accurate responses and faster solutions. My guess would be a wild pointer which you think it refers to the source data, when it may be nil or invalid.symbols is an NSMutableArray which contains 5 NSStrings.Code: Select all
-(NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox { NSUInteger number = [symbols count]; return number; } -(id)comboBox:(NSComboBox *)sender objectValueForItemAtIndex:(NSInteger)index { NSLog(@"%i", index); NSString *response = [symbols objectAtIndex:(int)index]; return response; }
well, at least i've found out why i get an exception: the index is out of bounds of the array. but the question is, WHY is the index out of bounds, and what can i do about it? i've tried out typecasts, but so far no luck. gonna keep trying...
"forgot to count in element zero"
so your first method tells you that there are 10 symbols so the number it returns is 10
however, element symbols [10] does not exist, and you never use symbols[0] since the array is from 0 to 9 = 10 elements
quick solution: without testing
Code: Select all
-(NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox {
NSUInteger number = [symbols count];
return number-1;
}
-(id)comboBox:(NSComboBox *)sender objectValueForItemAtIndex:(NSInteger)index {
NSLog(@"%i", index);
NSString *response = [symbols objectAtIndex:(int)index];
return response;
}
add your own code to prevent number from going "negative"
This is classic btw..
Cheers Frame
Bounty Scanner
Number 935
Number 935
i know all that, but it doesn't apply here. those methods are not called by my code, they are called by the combobox. it's how it knows what items to display when the user selects it.While my area is more c++, this looks like the classic
"forgot to count in element zero"
so your first method tells you that there are 10 symbols so the number it returns is 10
however, element symbols [10] does not exist, and you never use symbols[0] since the array is from 0 to 9 = 10 elements
besides, if that "element zero" stuff was the problem, it should work the first few times and then throw an exception. but instead i get the exception the first time, every time.
PS. did i mention this topic is for mac developers?
MacBook pro, OSX 10.8.5, Xcode 5
Well English is not my primary language, and yes I'm on windows and no you are not exactly coming of friendly like...harry747 wrote:i know all that, but it doesn't apply here. those methods are not called by my code, they are called by the combobox. it's how it knows what items to display when the user selects it.
besides, if that "element zero" stuff was the problem, it should work the first few times and then throw an exception. but instead i get the exception the first time, every time.
PS. did i mention this topic is for mac developers?
Bounty Scanner
Number 935
Number 935
the exception says the index is -1 which is obviously out of bounds. i've double-checked, i'm using the types that the documentation says i should use which is why i don't understand why the index is -1.Ahruman wrote:What index does it log before the exception is thrown?
MacBook pro, OSX 10.8.5, Xcode 5
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
I would expect -1 represents some special value, like a placeholder, but I can’t find any relevant documentation and it doesn’t happen in a test app I threw together.
I suggest adding the following at the top of your -comboBox:objectValueForItemAtIndex: and seeing if it shows up:
I suggest adding the following at the top of your -comboBox:objectValueForItemAtIndex: and seeing if it shows up:
Code: Select all
if (index < 0) return [NSString stringWithFormat:@"<< NEGATIVE: %li>>", index];
E-mail: [email protected]