I’m trying to create a UIButton programmatically. I have a button called “addCash” (which was already created in interface builder), upon tapping this button I want another button to dynamically appear. This button works fine when done in viewDidLoad, but this is not what I want as “addCash” needs to be tapped before this new button is to be created. This is what I have so far…
-(IBAction) addCash{
UIButton *theButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
theButton.frame = CGRectMake(80, 50, 150, 40);
[theButton setTitle:@"title" forState:UIControlStateNormal];
[theButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[theButton setBackgroundImage:[UIImage imageNamed:@"edit.jpg"] forState:UIControlStateNormal];
[self.view addSubview:theButton];
}
If you plain add a lot of buttons use
UITableViewwith custom cell. If you will just add new buttons to view you will get a performance issue – all you buttons will be loaded simultaneously.UITableViewcan manage this situation and unload unused cell’s.