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 09-11-2008, 07:59 AM   #1 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
Default Simple Loop Question..

I want to do a for loop (i am now going to try to implement a table view but am still curious) How can I increment the value of 'itemListText1' so it is 'itemListText%i'?

HTML Code:
//=======( create or destroy the text in field %i )=======
if ([mainDelegate.personArray count] == 1) {
	itemListText1.text = [NSString stringWithFormat:@"%@ - %@", [[mainDelegate.personArray objectAtIndex:0] itemTitle], [[mainDelegate.personArray objectAtIndex:0] itemAddtl]];
	itemListText2.text = [NSString stringWithFormat:@""];
//=========( corresponding delete buttons )==========
	remove1Button.hidden = YES;
	remove2Button.hidden = NO;
}
im sure its dead simple.. just create a variable and assign?

cheers.rob
roberthuttinger is offline   Reply With Quote
Old 09-11-2008, 09:53 AM   #2 (permalink)
Mobile Geek
 
Join Date: Aug 2008
Location: Florida, USA
Posts: 365
Send a message via AIM to rames44 Send a message via Yahoo to rames44
Default

Note sure exactly what "itemListText1" and "itemListText2", etc. are, but you could potentially have set your class up to use arrays instead of individual items.

itemListText[0], itemListText[1], etc.

There's nothing that says that the references to screen objects, etc. can't be held in arrays, although that might require creating the screen programmatically as opposed to using IB.
rames44 is offline   Reply With Quote
Old 09-11-2008, 10:00 AM   #3 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
Default

Quote:
Note sure exactly what "itemListText1" and "itemListText2" are
these are labels.

so you are saying write all the code for drwaing a label and store that code in an array replacing variable in the arraycode with varibles created on the fly?
roberthuttinger is offline   Reply With Quote
Old 09-11-2008, 10:04 AM   #4 (permalink)
I am evil trapper
 
Join Date: Jul 2008
Location: London
Posts: 299
Default

Interested to see how you go with this, make sure you post when you figure it out
trapper is offline   Reply With Quote
Old 09-11-2008, 10:08 AM   #5 (permalink)
Mobile Geek
 
Join Date: Aug 2008
Location: Florida, USA
Posts: 365
Send a message via AIM to rames44 Send a message via Yahoo to rames44
Default

Quote:
Originally Posted by roberthuttinger View Post
these are labels.
so you are saying write all the code for drwaing a label and store that code in an array replacing variable in the arraycode with varibles created on the fly?
I guess I don't understand enough of exactly what it is that you're trying to do.
rames44 is offline   Reply With Quote
Old 09-11-2008, 01:13 PM   #6 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
Default

right now I have an if statement for each comination, very ugly, very unprofessional. ;p
roberthuttinger is offline   Reply With Quote
Old 09-12-2008, 02:47 PM   #7 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
Default

so if i have an array that has 1 item in it, it will load the label with the text from a arrayItem[1] and show the delete button, and there is no info after that . so what id like to do is a for statement...
HTML Code:
for(i=0; i=arrayItems.count;i++) {
itemListText [###how do I increment this?###].text = [NSString stringWithFormat:@"%@ - %@", [[mainDelegate.personArray objectAtIndex:0] itemTitle], [[mainDelegate.personArray objectAtIndex:0] itemAddtl]];
remove2Button.hidden = NO;
}
How can I make the number of the label at the end a variable on the fly?

for example:
itemListText1
itemListText2
itemListText3 etc

rob
roberthuttinger is offline   Reply With Quote
Old 09-12-2008, 04:58 PM   #8 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 1,431
Default

Is this what you want?

Code:
	for (int i = 0; i <  10; i++)
	{
		NSString*	s = [NSString stringWithFormat:@"indexing title: %d", i];
		NSLog(@"%@", s);
	}
PhoneyDeveloper is offline   Reply With Quote
Old 09-12-2008, 06:05 PM   #9 (permalink)
Mobile Geek
 
Join Date: Aug 2008
Location: Florida, USA
Posts: 365
Send a message via AIM to rames44 Send a message via Yahoo to rames44
Default

Quote:
Originally Posted by roberthuttinger View Post
so if i have an array that has 1 item in it, it will load the label with the text from a arrayItem[1] and show the delete button, and there is no info after that . so what id like to do is a for statement...
HTML Code:
for(i=0; i=arrayItems.count;i++) {
itemListText [###how do I increment this?###].text = [NSString stringWithFormat:@"%@ - %@", [[mainDelegate.personArray objectAtIndex:0] itemTitle], [[mainDelegate.personArray objectAtIndex:0] itemAddtl]];
remove2Button.hidden = NO;
}
How can I make the number of the label at the end a variable on the fly?

for example:
itemListText1
itemListText2
itemListText3 etc

rob
So what's wrong with making "itemListText" an array (i.e. itemListText[3] instead of itemListText1, itemListText2 and itemListText3), making removeButton and array (i.e. removeButton[3] instead of remove1Button, remove2Button and remove3Button) and then doing:
Code:
for(i=0; i=arrayItems.count;i++) {
itemListText[i].text = [NSString stringWithFormat:@"%@ - %@", [[mainDelegate.personArray objectAtIndex:0] itemTitle], [[mainDelegate.personArray objectAtIndex:0] itemAddtl]];
removeButton[i].hidden = NO;
}
About the only issue I can think of is that you probably have to create the various items, buttons, etc. programmatically instead of creating them in InterfaceBuilder (since IB won't be able to inject into an array, I suspect) but that isn't hard. But that may actually be a good thing, since it would allow you to create the number of objects that match the number of items in your array, as opposed to having a fixed number.

Or am I just missing something fundamental in what you're trying to do?
rames44 is offline   Reply With Quote
Old 09-12-2008, 10:56 PM   #10 (permalink)
Registered Member
 
roberthuttinger's Avatar
 
Join Date: Sep 2008
Posts: 96
Default

Quote:
Or am I just missing something fundamental in what you're trying to do?
Its exactly what im trying to do and more to the point you touched on something I hadnt thought of. and that is to create the elements on the fly in code as opposed to in IB.

This makes more sense, even though its kinda simple to make buttons in IB and make connections. Im more of a visual kinda guy.

thanks for the suggestions and cleaner code than what was recently over 60 lines! It made me queasy just typing all that junk in knowing there was a better solution.

cheers.rob
roberthuttinger is offline   Reply With Quote
Reply

Bookmarks

Tags
array, button, loop, text

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: 247
23 members and 224 guests
ADY, Alsahir, beleg_1998, Dani77, diyora, FAED, fredidf, iDifferent, iph_s, JamesCahall, JasonR, mer10, Monstertaco, prchn4christ, Robiwan, Rudy, smithdale87, Speed, spiderguy84, stekki, tgjorgoski, timle8n1, twerner
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,880
Threads: 89,228
Posts: 380,755
Top Poster: BrianSlick (7,129)
Welcome to our newest member, @sandris
Powered by vBadvanced CMPS v3.1.0

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