【发布时间】:2011-11-28 17:57:55
【问题描述】:
我不知道这是否可能,但我想做的是在视图中多次添加子视图。我尝试过这样的事情:
[self.view addSubview: newView];
newView.center = CGPointMake(160, 100);
[self.view addSubview: newView];
newView.center = CGPointMake(160, 200);
[self.view addSubview: newView];
所有这些只是移动newView,而不添加新的。有什么想法吗?
我也试过这个:
[self.view addSubview:newView];
UIView *anotherView = newView;
anotherView.center = CGPointMake(160, 100)
[self.view addSubview:anotherView];
编辑
这是我随着时间的推移学到的解决方案
解决问题的另一种方法是制作一个包含视图的单独 nib,并多次添加 nib 的实例。实现此解决方案的一个很好的模板是按照在cellForRowAtIndexPath 方法中使用自定义UITableViewCell 的方式来完成。
【问题讨论】:
-
感谢您提出这个问题。这间接回答了我的一个问题!节省时间!哇哦!
标签: iphone objective-c ios cocoa-touch uiview