How to add same custom view as multiple times when clicking on add button. I tried to add using for loop but every times views are adding and overlapping previous views.
-
1) Create new variable each time. 2) Desgin view through coding or create a different class with xib.(Dont use view with IBOutlet Connection)Chanchal Warde– Chanchal Warde2017-05-17 08:27:35 +00:00Commented May 17, 2017 at 8:27
-
you need to remove previous view before add new custom view, or if you using story board designed view then also you need to remove and add sub view again with button presschirag bhalara– chirag bhalara2017-05-17 09:19:17 +00:00Commented May 17, 2017 at 9:19
-
removing is working but in views i hve text field so i remove the data is lost and new view is creating..Anu– Anu2017-05-17 10:54:57 +00:00Commented May 17, 2017 at 10:54
-
Create new variable each time is not working. 2)Yes using different xib. still no useAnu– Anu2017-05-17 11:11:25 +00:00Commented May 17, 2017 at 11:11
Add a comment
|
1 Answer
Like this:
-(IBAction)addNewCustomView {
YourView *view = [[YouView alloc] init];
// view.property = set
[self.view addSubview:view];
}
1 Comment
Anu
` for(int i=1;i<=inputNumber;i++){ CGRect frame = CGRectMake(5,i*120,backgroundView.frame.size.width-10,110); NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil]; customView = [ nibViews objectAtIndex: 0]; [customView setFrame:frame]; customView.delegate = self; [backgroundView addSubview:customView]; }`