when i run it in the simulator i always get terminating_due_to uncaught_exception, this block of code seems to be the problem.
qInput and aInput are UITextViews
and q and a are mutable arrays
Code:
- (IBAction)inputPressed:(id)sender
{
int i = 1;
q = [[NSMutableArray alloc]initWithCapacity:20];
a = [[NSMutableArray alloc]initWithCapacity:20];
[[q objectAtIndex:i]setText:qInput.text];
[[a objectAtIndex:i]setText:aInput.text];
i++;
}
whats wrong?
canzhi
I'm not sure about this, but it might be since you are allocated and init them, all 20 objects are = nil. You can't try to setText of nil. Instead, do this:
Code:
if (q == nil) {
q = [[NSMutableArray alloc]initWithCapacity:20];
} if (a == nil) {
a = [[NSMutableArray alloc]initWithCapacity:20];
}
good point...but it still doesnt work.
ive found out that the code stops at this line
Code:
[[q objectAtIndex:i]setText:qInput.text];
Well if you only want to copy the text from your UITextView's, why do you need an array? Are you keeping a history of everything you copy? Sorry if I missed something, it just seems like you're overcomplicating things.
The error message is quite clear. The objcects you're adding to the array are strings, you're sending the NSString objects a SetText message. NSString doesn't recognize any such method.
What is I you're actually trying to do? The code doesn't really make sense as it is.
PS. You could replace "setText:" with "addObject:" but without knowing what you're trying to achieve I can't say if that's the correct solution or not.
(and remove the addObject limes from the other method)
PS. You could replace "setText:" with "addObject:" but without knowing what you're trying to achieve I can't say if that's the correct solution or not.
(and remove the addObject limes from the other method)
basically, im trying to save text from uitextview into an array
basically, im trying to save text from uitextview into an array
ok so i replaced setText with addObject and removed addObject from the other lines and im not getting that error message anymore, but in the debugger it still says that q has 0 objects........
ok so i replaced setText with addObject and removed addObject from the other lines and im not getting that error message anymore, but in the debugger it still says that q has 0 objects........