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 04-10-2011, 01:51 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 13
lll3mk4 is on a distinguished road
Default nsmutablearray help

Hello I would like to make an NSmutableArray and add 3 text fields to the NSmutableArray so I dont need to repeat this code three times.

if ([textfield1.text length] >= 3) {

textfield1.text = [textfield1.text substringWithRange:NSMakeRange(0,2)];

But when ever I add the three text fields to the NSmutableArray it wont let me replace the "textfield1.text" with "NSmutableArray.text" why is this? Is there another way that might solve my problem!


Thanks
lll3mk4 is offline   Reply With Quote
Old 04-10-2011, 02:09 AM   #2 (permalink)
noob iphone developer
 
Join Date: Jul 2008
Location: Denmark
Posts: 237
Trisect Development is on a distinguished road
Default

Quote:
Originally Posted by lll3mk4 View Post
Hello I would like to make an NSmutableArray and add 3 text fields to the NSmutableArray so I dont need to repeat this code three times.

if ([textfield1.text length] >= 3) {

textfield1.text = [textfield1.text substringWithRange:NSMakeRange(0,2)];

But when ever I add the three text fields to the NSmutableArray it wont let me replace the "textfield1.text" with "NSmutableArray.text" why is this? Is there another way that might solve my problem!


Thanks
Use [NSMutableArray ObjectAtIndex:index]
Trisect Development is offline   Reply With Quote
Old 04-10-2011, 07:07 AM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by lll3mk4 View Post
Hello I would like to make an NSmutableArray and add 3 text fields to the NSmutableArray so I dont need to repeat this code three times.

if ([textfield1.text length] >= 3) {

textfield1.text = [textfield1.text substringWithRange:NSMakeRange(0,2)];

But when ever I add the three text fields to the NSmutableArray it wont let me replace the "textfield1.text" with "NSmutableArray.text" why is this? Is there another way that might solve my problem!


Thanks

Mutable arrays don't have a text property. NSMutableArrays contain arrays of other objects. Sometimes those objects are strings, sometimes other kinds of objects.

What is it you want? The string object at a particular index, or all the strings at all the array indexes combined together?

If you just need one of the strings at a particular index, you could use something like

Code:
[myArray objectAtIndex: index];  //My array is a mutable array created elsewhere
As the other poster said.

If you want to combine all the strings together, you need to write code to do that.

Something like this:

Code:
NSMutableString* combinedString;

combinedString = [NSMutableString stringWithCapacity: 50];
NSString* aString;
for (aString in myArray)
   [combinedString appendString: aString];
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmutablearray, textfield

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: 366
13 members and 353 guests
dansparrow, dre, ilmman, LezB44, michelle, Nobbsy, Objective Zero, oztemel, samdanielblr, Sami Gh, shagor012, sledzeppelin, thephotographer
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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