Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2010, 06:21 PM   #1 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default Need help with copying text from UITextView to an array.

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
cye is offline   Reply With Quote
Old 03-18-2010, 10:00 PM   #2 (permalink)
iPhone SDK learner
 
Join Date: Feb 2010
Location: Illinois, USA
Posts: 417
Default

Quote:
Originally Posted by cye View Post
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];
}
Batman is offline   Reply With Quote
Old 03-18-2010, 10:45 PM   #3 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default hmmmm...

good point...but it still doesnt work.
ive found out that the code stops at this line
Code:
	[[q objectAtIndex:i]setText:qInput.text];
cye is offline   Reply With Quote
Old 03-18-2010, 11:17 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 126
Default

Quote:
Originally Posted by cye View Post
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.
javaconvert is offline   Reply With Quote
Old 03-19-2010, 01:13 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 187
Default

[q objectAtIndex:i] doesn't exist, until you add something to the array.

It doesn't look like you've added anything to the array, and yet you're trying to access objects in it.
Son of a Beach is offline   Reply With Quote
Old 03-19-2010, 09:53 AM   #6 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default

Quote:
Originally Posted by Son of a Beach View Post
[q objectAtIndex:i] doesn't exist, until you add something to the array.

It doesn't look like you've added anything to the array, and yet you're trying to access objects in it.
so how do i add (20) objects to the array?
cye is offline   Reply With Quote
Old 03-19-2010, 10:11 AM   #7 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,886
Default

with addObject:
harrytheshark is offline   Reply With Quote
Old 03-19-2010, 06:44 PM   #8 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default lalala still have problems

Quote:
Originally Posted by harrytheshark View Post
with addObject:
ok i added objects and i initialized the array but im still getting "___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___"

is there something wrong with this?
q and a are arrays and qInput and aInput are both UITextViews, and i is an int
Code:
[[q objectAtIndex:i]setText:qInput.text];
[[a objectAtIndex:i]setText:aInput.text];
whats wrong? ahh
cye is offline   Reply With Quote
Old 03-19-2010, 10:21 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 187
Default

Quote:
Originally Posted by cye View Post
ok i added objects and i initialized the array but im still getting "___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___"

is there something wrong with this?
q and a are arrays and qInput and aInput are both UITextViews, and i is an int
Code:
[[q objectAtIndex:i]setText:qInput.text];
[[a objectAtIndex:i]setText:aInput.text];
whats wrong? ahh
Show us the code. We can't comment on code we've not seen. Show us the relevant code now that you're adding objects to he array.
Son of a Beach is offline   Reply With Quote
Old 03-19-2010, 11:40 PM   #10 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default heres some code

Quote:
Originally Posted by Son of a Beach View Post
Show us the code. We can't comment on code we've not seen. Show us the relevant code now that you're adding objects to he array.

Code:
- (IBAction)toReviewPressed:(id)sender
{
	if (q == nil) {
		q = [[NSMutableArray alloc]init];
	} if (a == nil) {
       	a = [[NSMutableArray alloc]init];
	}

        objq = @"";
	obja = @"";
	
	[q addObject:objq];
	[a addObject:obja];
	
	
	i = 1;
}


- (IBAction)inputPressed:(id)sender
{	
	qText = [[NSString alloc] initWithFormat:qInput.text];
	aText = [[NSString alloc] initWithFormat:aInput.text];
	
	
	[[q objectAtIndex:i]setText:(NSString *) qText];
	[[a objectAtIndex:i]setText:(NSString *) aText];
	
	i++;
}
i have objq, obja, q, a, and i declared in the .h file
cye is offline   Reply With Quote
Old 03-19-2010, 11:56 PM   #11 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default reason given by debugger console

Quote:
Originally Posted by cye View Post
Code:
- (IBAction)toReviewPressed:(id)sender
{
	if (q == nil) {
		q = [[NSMutableArray alloc]init];
	} if (a == nil) {
       	a = [[NSMutableArray alloc]init];
	}

        objq = @"";
	obja = @"";
	
	[q addObject:objq];
	[a addObject:obja];
	
	
	i = 1;
}


- (IBAction)inputPressed:(id)sender
{	
	qText = [[NSString alloc] initWithFormat:qInput.text];
	aText = [[NSString alloc] initWithFormat:aInput.text];
	
	
	[[q objectAtIndex:i]setText:(NSString *) qText];
	[[a objectAtIndex:i]setText:(NSString *) aText];
	
	i++;
}
i have objq, obja, q, a, and i declared in the .h file

2010-03-19 22:55:15.299 FlashCards[3307:20b] *** -[NSCFString setText:]: unrecognized selector sent to instance 0x4030
2010-03-19 22:55:15.301 FlashCards[3307:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString setText:]: unrecognized selector sent to instance 0x4030'
2010-03-19 22:55:15.303 FlashCards[3307:20b] Stack: (
807902715,
2520190523,
808284155,
807854166,
807706786,
10641,
814709201,
815110321,
815119058,
815114270,
814813151,
814722763,
814748641,
839148405,
807687520,
807683624,
839142449,
839142646,
814752238
)
Current language: auto; currently objective-c
(gdb)
cye is offline   Reply With Quote
Old 03-20-2010, 06:08 AM   #12 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 187
Default

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.
Son of a Beach is offline   Reply With Quote
Old 03-20-2010, 06:12 AM   #13 (permalink)
Registered Member
 
Join Date: Aug 2009
Location: Tasmania, Australia
Posts: 187
Default

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)
Son of a Beach is offline   Reply With Quote
Old 03-20-2010, 01:22 PM   #14 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default

Quote:
Originally Posted by Son of a Beach View Post
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
cye is offline   Reply With Quote
Old 03-20-2010, 01:30 PM   #15 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default

Quote:
Originally Posted by cye View Post
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........
cye is offline   Reply With Quote
Old 03-20-2010, 02:05 PM   #16 (permalink)
cye
14 Year Old App Developer
 
Join Date: Mar 2010
Location: Texas
Posts: 242
Default YES!

Quote:
Originally Posted by cye View Post
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........
i got it! thanks very much for everyone's help!
cye is offline   Reply With Quote
Old 11-18-2010, 02:17 AM   #17 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 10
Default

I had the same problem, I used SetText and it worked. Thanks
__________________
Apple store : enemy of friend ?
iphone casino
sebastien is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, nsmutablearray, settext, uitextview, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 264
23 members and 241 guests
ADY, bookesp, chillyh, ckgni, dacapo, Dani77, Davey555, Desert Diva, glenn_sayers, HemiMG, jakerocheleau, JasonR, LEARN2MAKE, mer10, nobre84, prchn4christ, Raggou, Rudy, ryantcb, Speed, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:37 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0