在我的应用中,有一部分必须在按下按钮时重复。也就是说,UIView,有几个文本字段,只要按下按钮就应该无限重复。为了更好地理解它,我正在上传一个"演示视图"页面和我用来实现它的代码。我能够复制视图和标签,但UIButton不会重复。
- (void)viewDidLoad {
[super viewDidLoad];
_testView.backgroundColor=[UIColor blackColor];
[_testView addSubview:_labelRef];
[_testView addSubview:_buttonRef];
[self.view addSubview:_testView];
_lastView=_testView;
_archievedData=[NSKeyedArchiver archivedDataWithRootObject:_testView];
// Do any additional setup after loading the view.
}
- (IBAction)repeatButton:(id)sender {
UIView *newView=[NSKeyedUnarchiver unarchiveObjectWithData:_archievedData];
CGRect newFrame;
newFrame.origin.x=newView.frame.origin.x;
newFrame.origin.y=(newView.frame.origin.y + newView.bounds.size.height);
newFrame.size.height=newView.frame.size.height;
newFrame.size.width=newView.frame.size.width;
newView.frame=newFrame;
newView.backgroundColor=[UIColor greenColor];
[self.view addSubview:newView];
_archievedData=[NSKeyedArchiver archivedDataWithRootObject:newView];
}
我该如何解决这个问题?