【发布时间】:2013-05-24 14:54:32
【问题描述】:
我在 xib 中创建了一个视图,其中 UIImageviews 和 UILabel 作为子视图。从我的代码中,是否可以在每次运行循环时创建一个新的视图对象。请帮助我。
【问题讨论】:
我在 xib 中创建了一个视图,其中 UIImageviews 和 UILabel 作为子视图。从我的代码中,是否可以在每次运行循环时创建一个新的视图对象。请帮助我。
【问题讨论】:
您需要创建一个名为 CustomView 的新自定义视图 在XIB中选择类到CustomView。
然后将 XIB 名称加载到 View 对象中并可以循环使用
CustomView *aView = [[[NSBundle mainBundle] loadNibNamed:@"YourXibName" owner:nil options:nil] objectAtIndex:0];
【讨论】:
当您创建视图并通过界面构建器将其连接起来后,您可以轻松添加视图,例如
for(int i = 0; i < numberOfIterations; i++){
UIView * newView = [[UIView alloc] initWithFrame:MyFrame];
[myInterfaceBuilderView addSubview:newView];
}
【讨论】: