基本上,我的问题是我试图通过循环创建 3 个 UIView 实例。我正在使用 ARC,我真的不知道我想做的事情是否可行。这是我目前拥有的代码:
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"RoomView"
owner:self
options:nil];
NSMutableArray *roomViews = [[NSMutableArray alloc] initWithCapacity:[gtb.rooms count]];
for (i = 0; i < [gtb.rooms count]; i++)
{
RoomView *rcv = [[RoomView alloc] init];
NSDictionary *room = [gtb.rooms objectAtIndex:i];
rcv = [nibViews objectAtIndex:0];
NSLog(@"Start rcv = %@", rcv);
rcv.roomNumber.text = [NSString stringWithFormat:@"Chambre %d", i + 1];
rcv.roomType.text = [room objectForKey:@"roomType"];
[rcv setFrame:CGRectMake(0, sizeOfContent, rcv.frame.size.width, rcv.frame.size.height)];
sizeOfContent += rcv.frame.size.height;
[roomViews addObject:rcv];
NSLog(@"End rcv = %@", rcv);
}
for (i = 0; i < [gtb.rooms count]; i++)
NSLog(@"Room #%i : %@", i, [roomViews objectAtIndex:i]);
这是我在日志中的内容:
2012-09-20 10:15:00.287 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 0; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.289 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 420; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.312 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 420; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.314 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 527; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.316 AppName[2792:707] Start rcv = <RoomView: 0x148570; frame = (0 527; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.317 AppName[2792:707] End rcv = <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.319 AppName[2792:707] Room #0 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.323 AppName[2792:707] Room #1 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
2012-09-20 10:15:00.325 AppName[2792:707] Room #2 : <RoomView: 0x148570; frame = (0 634; 320 107); autoresize = W+H; layer = <CALayer: 0x148510>>
我知道如果我没有使用 ARC,我应该[rcv autoRelease]
在循环末尾放置类似的东西,但是使用 ARC,我不能。
有什么解决方案可以解决它,还是我必须为此文件禁用 ARC?
谢谢你的帮助 !