I have a scrollview. I add a button for this scroll and release it after.
UIButton * saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
saveButton.frame = CGRectMake(415.0, 473, 80, 38);
saveButton.titleLabel.font = [UIFont fontWithName:@"Heiti TC" size:24];
[saveButton setTitle:@"" forState:UIControlStateNormal];
[saveButton setContentEdgeInsets:UIEdgeInsetsMake(2, 0, 0, 0)];
saveButton.backgroundColor = [UIColor clearColor];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
[saveButton setBackgroundImage:[UIImage imageNamed:@"save.png"] forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
saveButton.hidden = NO;
[self.scrollview addSubview:saveButton];
[saveButton release];
The application crashes when the view is displayed on the screen, and I try to touch any part of the screen.
If I comment
[saveButton release]
The application works fine.
I thought that the number of button holds would increase as soon as I added it to the scrollview so that it would be safe to release the button.
What's going on here? Is adding something to scrollview not the same as adding it to the main view, as shown below?
[self.view addSubview:saveButton]
user440096
source
share