0
我有一個小的子類UIView,用於在連接超時時向用戶顯示「連接超時」動畫。我在該方法中添加了一些代碼:scrollViewDidScroll,以便當用戶滾動表格時,子視圖在呈現時不會滾動。但是,當連接超時視圖完成動畫並且視圖從超級視圖中移除時,無論何時滾動tableview,我都會收到一條消息,發送到解除分配的實例錯誤。我進行了檢查,看看子視圖是否爲零,但似乎沒有工作。我將如何避免這種情況?iOS檢查視圖是否仍然存在
如何呈現子視圖:
// Show No Internet Message
noInternetView = [FCDataController presentNoInternetMessage:self.view];
noInternetViewOrigin = noInternetView.frame.origin;
視圖是如何顯示在我的FCDataController類:
+ (NoInternetView *)presentNoInternetMessage:(UIView *)view {
NoInternetView *internet = [[NoInternetView alloc] initWithFrame:CGRectMake(0, view.bounds.size.height, view.bounds.size.width, 30) andPosition:NoInternetPositionBottom];
[view addSubview:internet];
CGRect position = CGRectMake(0, view.bounds.size.height - 30, view.bounds.size.width, 30);
[UIView animateWithDuration:0.4
delay:0.5
options:UIViewAnimationOptionCurveEaseOut
animations:^{
internet.frame = position;
}
completion:^(BOOL finished) {
NSLog(@"DONE");
[self performSelector:@selector(hideInternetMessageForView:) withObject:view afterDelay:2.0];
}];
return internet;
}
+ (BOOL)hideInternetMessageForView:(UIView *)view {
NoInternetView *internet = [self NoInternetForView:view];
if (internet != nil) {
CGRect remove = CGRectMake(0, view.bounds.size.height, view.bounds.size.width, 30);
[UIView animateWithDuration:0.5
delay:1.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
internet.frame = remove;
}
completion:^(BOOL finished) {
NSLog(@"DONE");
[internet removeFromSuperview];
}];
return YES;
}
return NO;
}
+ (NoInternetView *)NoInternetForView:(UIView *)view {
NoInternetView *internet = nil;
NSArray *subviews = view.subviews;
Class internetClass = [NoInternetView class];
for (UIView *aView in subviews) {
if ([aView isKindOfClass:internetClass]) {
internet = (NoInternetView *)aView;
}
}
return internet;
}
ScorllView方法:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (noInternetView != nil) {
noInternetView.frame = CGRectMake(self.noInternetViewOrigin.x, self.noInternetViewOrigin.y + self.tableView.bounds.origin.y, noInternetView.frame.size.width, noInternetView.frame.size.height);
}
}
我修復它,而不是初始化它與self.parentViewController.view不Self.view,它的作品完美! – 2013-03-13 01:41:07