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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 10-18-2010, 02:06 PM   #1 (permalink)
Yko
Registered Member
 
Join Date: Sep 2010
Posts: 26
Yko is on a distinguished road
Default EXC BAD ACCESS from UITextField with spaces in it

Hey guys,

I noticed something interesting.

I have an Item class and one of its parameters is

NSString *name;

In a UITextField, I have this code:

Quote:
- (BOOL)textFieldShouldReturnUITextField *)textField
{
// name is defined in .h as NSString *name;
[nameTF resignFirstResponder];
name = nameTF.text;
NSLog(@"name from UITextField is %@", name);
return YES;
}
then later on,

Quote:
-(IBAction)donePressed
{
[newItem setName:name];
[newItem setQuantity:quantity];
[newItem setStatus:status];

// pop the view from the Navigation stack
[[self navigationController] popViewControllerAnimated:TRUE];
}
Now, in the UITextField, if I type item1, it works. However, when I type item 1 with a space between item and 1, it gives EXC BAD ACCESS error.

I'm a little stumped because I thought it's a string and spaces are allowed. Any ideas?

Thanks!
Yko is offline   Reply With Quote
Old 10-18-2010, 04:04 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

name = nameTF.text;

This is wrong. You need to do some research on memory management and properties in objective c.
smithdale87 is offline   Reply With Quote
Old 10-18-2010, 04:26 PM   #3 (permalink)
Yko
Registered Member
 
Join Date: Sep 2010
Posts: 26
Yko is on a distinguished road
Default

Quote:
Originally Posted by smithdale87 View Post
name = nameTF.text;

This is wrong. You need to do some research on memory management and properties in objective c.
OK. I changed it to

name = [NSString stringWithString:[name text]];

Still, doesn't work.
Yko is offline   Reply With Quote
Old 10-18-2010, 04:27 PM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

of course not

try something else
smithdale87 is offline   Reply With Quote
Old 10-18-2010, 04:36 PM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 651
kapps11 is on a distinguished road
Default

I like the game slicks playing haha. Look at Slick's guide to properties on this forum to help you out. And also in the delegate method why don't you just use the textfield object that it passes to you instead of nameTF? Its better programming practice. Just a thought...
kapps11 is offline   Reply With Quote
Old 10-19-2010, 08:46 AM   #6 (permalink)
Yko
Registered Member
 
Join Date: Sep 2010
Posts: 26
Yko is on a distinguished road
Default

OK. Let's see if I got this right. I changed it to:


Quote:
- (BOOL)textFieldShouldReturnUITextField *)textField
{
[textField resignFirstResponder];
[self setName:[textField text]];
NSLog(@"name from UITextField is %@", name);
return YES;
}
I reread Rames44 on the tutorial section of the forums. I read it twice before but keep forgetting. Orginally, I keep trying [name setText:@"string"] because I though that "name" is a string object and I can get/set as long as I synthesize.

Let me know if I'm still wrong. Thanks smith and kapps, really appreciate it. Still learning.

One other question. If I have multiple UITextField and I use [textField resignFirstResponder] does it always assign the keyboard/UITextField as the first responder and knows how to resign it?

Thanks.
Yko is offline   Reply With Quote
Reply

Bookmarks

Tags
exc_bad_access, uitextfield

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: 336
7 members and 329 guests
Desert Diva, dre, hain, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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