在此先感謝。UITableView在互聯網連接丟失後不顯示
我正在使用Apple的Reachability Class文件來獲取Internet狀態。當互聯網處於活動狀態時,我將調用webservie並將響應數據存儲在sqlite3數據庫中並顯示在UITableView中。當互聯網丟失我從數據庫中檢索數據並在UITableView中顯示它,然後UITableView沒有顯示數據,但總代碼工作正常。我不知道爲什麼會這樣,請幫助我。這是我的代碼
爲了檢查互聯網我已經寫了下面的代碼在viewWillAppear中:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus:) name:kReachabilityChangedNotification object:nil];
internetReach = [Reachability reachabilityForInternetConnection];
[internetReach startNotifier];
hostReach = [Reachability reachabilityWithHostName:@"www.kluebook.com"];
[hostReach startNotifier];
這是我在showData方法寫入
- (void)checkNetworkStatus:(NSNotification *)notice {
NetworkStatus internetStatus = [internetReach currentReachabilityStatus];
switch (internetStatus) {
case NotReachable:
self.internetActive = NO;
break;
case ReachableViaWiFi:
self.internetActive = YES;
break;
case ReachableViaWWAN:
self.internetActive = YES;
break;
}
NetworkStatus hostStatus = [hostReach currentReachabilityStatus];
switch (hostStatus) {
case NotReachable:
self.hostActive = NO;
break;
case ReachableViaWiFi:
self.hostActive = YES;
break;
case ReachableViaWWAN:
self.hostActive = YES;
break;
}
if (internetActive && hostActive) {
for (UIButton *subView in [self.view subviews]) {
if ([subView isKindOfClass:[UIButton class]] && subView.tag == 1001) {
[subView removeFromSuperview];
}
}
[self showSpinner];
if (viewTag == 2009) {
[self performSelectorInBackground:@selector(stopSpinnig) withObject:nil];
NSUserDefaults* ud = [NSUserDefaults standardUserDefaults];
[ud setObject:[NSNumber numberWithInteger:0] forKey:@"viewTag"];
[ud synchronize];
}
else {
[self getLoadingData];
}
createCardBtn.enabled = YES;
}
if (self.internetActive == NO) {
createCardBtn.enabled = NO;
for (EGORefreshTableHeaderView *view in [cardsTableView subviews]) {
[view removeFromSuperview];
}
_refreshHeaderView = nil;
[_refreshHeaderView removeFromSuperview];
networkStatusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
networkStatusBtn.userInteractionEnabled = NO;
networkStatusBtn.frame = CGRectMake(0, 66, 320, 40);
[networkStatusBtn setImage:[UIImage imageNamed:@"warning.png"] forState:UIControlStateNormal];
[networkStatusBtn setTitle:@"No Internet Connection" forState:UIControlStateNormal];
networkStatusBtn.imageEdgeInsets = UIEdgeInsetsMake(5, 65, 5, 225);
networkStatusBtn.titleEdgeInsets = UIEdgeInsetsMake(10, 55, 10, 65);
networkStatusBtn.backgroundColor = [UIColor blackColor];
networkStatusBtn.titleLabel.textColor = [UIColor whiteColor];
networkStatusBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0];
networkStatusBtn.tag = 1001;
[self.view addSubview:networkStatusBtn];
resultArray = [sql getAllCardsBasedOnType:701];
if (resultArray.count == 0) {
filterBtn.enabled = NO;
cardsTableView.backgroundView = bgImageView;
[cardsTableView setScrollEnabled:NO];
}
else {
filterBtn.enabled = YES;
[cardsTableView setScrollEnabled:YES];
//cardsTableView.backgroundColor = [UIColor clearColor];
[self performSelectorOnMainThread:@selector(showTheData) withObject:nil waitUntilDone:YES];
}
if (isLoaderViewShowing == YES) {
[loaderView removeFromSuperview];
isLoaderViewShowing = NO;
}
}
}
方法我只是重新加載表視圖[cardTableView reloadData];
這是什麼應該做的:'爲(EGORefreshTableHeaderView *在[cardsTableView子視圖]視圖){ [查看removeFromSuperview] }'? –
基本上,我刪除拉來刷新視圖,我已經添加了UITableViewHeaderView @ alex-i – Vishnu