【发布时间】:2014-02-27 18:29:19
【问题描述】:
我有一个方法是我正在创建 UIView,当我从 IBAction 调用它时它工作正常。但是当我再次调用相同的方法时,它会在顶部绘制另一个视图,我相信这是内存泄漏。如何在创建另一个 UIView 之前删除以前的 UIView?谢谢!
- (int)showQuestionMethod:(int)number;
{
UIView *questionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 500, 250)];
questionView.backgroundColor = [[UIColor alloc] initWithRed:0.93 green:0.93
blue:0.93 alpha:1.0];
[self.view addSubview:questionView];
questionView.tag = questionNumber;
UILabel *questionLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 280, 0)];
questionLabel.text = question1;
[questionView addSubview:questionLabel];
CGRect frame = questionView.frame;
frame.size.height = questionHeight;
questionView.frame = frame;
questionView.tag = questionNumber;
return currentQuestion;
}
- (IBAction)nextQuestion:(id)sender {
[self showQuestionMethod:questionNumber];
}
【问题讨论】:
标签: ios objective-c uiview