我想删除不再需要的currencyViews(tableViews)。我可以动态地改变它们,如果我有6个currencyViews,现在是4个,那么2个(未显示)仍然存在。我怎么能删除它们?
- (void)loadScrollViewWithPage:(int)page {
if (page < 0) return;
if (page >= numberOfCurrencyViews) return;
// replace the placeholder if necessary
CurrencyViewController *controller = [self.currencyControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null]) {
controller = [[CurrencyViewController alloc] initWithPageNumber:page];
controller.delegate = self;
[self.currencyControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// add the controller's view to the scroll view
if (nil == controller.view.superview)
{
CGRect frame = scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[scrollView addSubview:controller.view];
}
}
答案 0 :(得分:2)
您可以使用以下内容删除视图中的子视图:
[controller.view removeFromSuperview];
答案 1 :(得分:0)
[myScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];