我正在使用 xib 为我的项目创建视图。条件是:
我有多个UIView
IBoutlet 的对象。
IBOutlet UIView *viewOpenDoor;
IBOutlet UIView *viewOpenDoor_Second;
viewOpenDoor
仅连接到 xib 中的视图之一。viewdidload
现在我正在使用此代码在方法中多次重用相同的视图-
[viewOpenDoor setFrame:CGRectMake(30, 80, viewOpenDoor.frame.size.width, viewOpenDoor.frame.size.height)];
[self.view addSubview:viewOpenDoor];
viewOpenDoor.layer.borderColor = [UIColor blackColor].CGColor;
viewOpenDoor.layer.borderWidth = 0.9f;
viewOpenDoor.layer.cornerRadius = 6.0f;
[viewOpenDoor setHidden:YES];
viewOpenDoor_Second = [[UIView alloc] init];
viewOpenDoor_Second = [viewOpenDoor copy];
[viewOpenDoor_Second setFrame:CGRectMake(184, 80, viewOpenDoor.frame.size.width, viewOpenDoor.frame.size.height)];
[self.view addSubview:viewOpenDoor_Second];
它给出了例外-
-[UIView copyWithZone:]: unrecognized selector sent to instance 0x95ba140
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView copyWithZone:]: unrecognized selector sent to instance 0x95ba140'
所以,我的问题是如何重复使用IBOutlet
在 xib 中创建的这个对象,多次使用不同的实例?