0

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.

4
  • 1) Create new variable each time. 2) Desgin view through coding or create a different class with xib.(Dont use view with IBOutlet Connection) Commented 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 press Commented 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.. Commented May 17, 2017 at 10:54
  • Create new variable each time is not working. 2)Yes using different xib. still no use Commented May 17, 2017 at 11:11

1 Answer 1

1

Like this:

-(IBAction)addNewCustomView {

  YourView *view = [[YouView alloc] init];
  // view.property = set
  [self.view addSubview:view];

}
Sign up to request clarification or add additional context in comments.

1 Comment

` 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]; }`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.