Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I´m a newbee to iOS Programming and i need a little help.

I know the subject isn´t possible - but how would you do this the easiest way?:

I have a playlist of 20 different players - witch i need to give a name, so i created 20 different text fields in interface builder
and assigned them in the header file like this:
CSS
IBOutlet UITextField *player1;
IBOutlet UITextField *player2;
IBOutlet UITextField *player3;
IBOutlet UITextField *player4;
IBOutlet UITextField *player5;
and so on....


and every outlet is assigned to a text field

i store these values and come back later to edit the names and what i really want is something like this:

for (int i = 0; i<20;i++)
{
player{i+1}.text = [playerlist objectatindex:i];
}


wich i know isn't possible - but how is this done the easiest way then ?
in stead of the manual way:

CSS
player1.text = [playlist objectAtIndex:0];
player2.text = [playlist objectAtIndex:1];
player3.text = [playlist objectAtIndex:2];
player4.text = [playlist objectAtIndex:3];
player5.text = [playlist objectAtIndex:4];
player6.text = [playlist objectAtIndex:5];



Br
Michael
Posted

1 solution

This simply illustrates the fact that "writing" code with interface builder has it deadly sins which should be avoided.

Don't rely on all those "interface builders", "Designers" and other stuff designed to please the weak-minded :-) in serious work. While helping in designing something visual — to certain extent, those tools create absolutely non-supportable code and problems like yours. Marketing people pretend that would they promote "automates" programming, but in fact it makes the programming much more manual and suggests an inexperience developer to repeat the same mouse click to create identical code instead of using various kind of abstraction and simple parametrization.

You case is a bright example of such a false "help" from an interface builder. If you programmed your functionality manually, you could find an automated solution of your problem. In particular, look — you have 6 player objects. This is already bad; really maintainable code should be abstracted from the constant 6, I mean, this constant should be a parameter of design — you change it and get any number of objects.

In your case, you could easily use the array of pointers to players. For code examples, see:
http://stackoverflow.com/questions/1123434/objective-c-how-to-implement-an-array-of-pointers-in-a-method-declaration[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900