我创建了一堆文本区域。我正在堆叠他们垂直,所以我使用:想创建一个变量,增加它并获得新值
CGRectMake(193, ((i * 45) + 45), 240, 30)
然后每个文本框创建后,我增加i。
int i = 0
CGRect myRect = CGRectMake(193, ((i * 45) + 45), 240, 30)
UITextField *myTextField01 = [[UITextField alloc] initWithFrame:myRect];
//format and add to view text field
i++;
//create next text field
myRect = CGRectMake(193, ((i * 45) + 45), 240, 30) //can i get rid of this line?
UITextField *myTextField01 = [[UITextField alloc] initWithFrame:myRect];
//format and add to view text field
i++;
我需要重新分配myRect得到我更新到1
值有没有更好的办法做到这一点,所以我不需要重新分配myRect获得的更新值一世?
这个效果很好,我不得不每次重新分配myRect,并用这个代替i ++。 – Padin215
很高兴为您提供帮助,但我向您保证,重新分配CGRect结构的“成本”非常接近于零,您应该没有理由担心它。谨防[过早优化](http://en.wikipedia.org/wiki/Program_optimization#When_to_optimize)! –
呵呵,是不是我要优化,我只是厌倦了copyig /粘贴那么多行= D – Padin215