Xcode 4变量变量名 [英] Xcode 4 variable variable names

查看:108
本文介绍了Xcode 4变量变量名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我是iOS编程的新手,我需要一点帮助.

我知道这是不可能的-但是您将如何以最简单的方式做到这一点?:

我有一个包含20个不同播放器的播放列表-我需要给个名字,所以我在界面生成器中创建了20个不同的文本字段
并将它们分配到头文件中,如下所示:

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:

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:

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




Br
Michael

推荐答案

这仅说明了以下事实:使用接口构建器编写"代码有致命的缺点,应避免.

不要依赖所有那些界面构建者",设计师"和其他旨在取悦弱者的东西:-)在认真的工作中.在帮助设计视觉效果的同时,在一定程度上,这些工具会创建绝对无法支持的代码和类似您的问题.营销人员假装他们会促进自动化"编程,但实际上它会使编程成为much more manual,并建议没有经验的开发人员重复单击同一鼠标来创建相同的代码,而不是使用各种抽象和简单的参数化. />
您的案例是接口构建器提供的此类虚假帮助"的一个很好的例子.如果您手动编程功能,则可以找到问题的自动解决方案.特别是外观-您有6个玩家对象.这已经很糟糕了.真正可维护的代码应该从常量6中抽象出来,我的意思是,该常量应该是设计的一个参数—您可以对其进行更改并获取任意数量的对象.

就您而言,您可以轻松地使用指向玩家的指针数组.有关代码示例,请参见:
http://stackoverflow. com/questions/1123434/objective-c-how-to-implement-an-array-of-pointers-in-a-method-declaration [
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


这篇关于Xcode 4变量变量名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆