2010-07-10 40 views
1

我有一個UITableView,如果存在活動的網絡連接,它將獲取數據填充。當沒有連接時,我想添加一個視圖到當前的視圖,它會顯示沒有Internet連接。與沒有同步照片時的照片應用類似。我不知道我該如何做到這一點。如何添加UITableView的subview ontop?

回答

0

這不完全是你想要的,但你可以有一個「空數據」表視圖,足夠的單元格也允許滾動,並且第一個單元格包含像「無網絡連接」的消息。

另一種方法是將表視圖放置在另一個(父)視圖中,並在沒有網絡時將該(子)表視圖替換爲空視圖。

0

一般來說,蘋果建議爲此設置UIAlertView。開發人員中心的示例通常具有UIAlertViews,這只是因爲Apple認爲網絡需求應用程序中網絡可用性的缺乏足以提醒用戶注意。

我用下面(保持完整版權當然)

UIAlertView+Helper.h

// 
// UIAlertViewHelper.h 
// CocoaHelpers 
// 
// Created by Shaun Harrison on 10/16/08. 
// Copyright 2008 enormego. All rights reserved. 
// 

#import <UIKit/UIKit.h> 

/* 
* Convenience method to throw a quick alert to the user 
*/ 
void UIAlertViewQuick(NSString* title, NSString* message, NSString* dismissButtonTitle); 

@interface UIAlertView (Helper) 

@end 

UIAlertView+Helper.m

// 
// UIAlertViewHelper.m 
// CocoaHelpers 
// 
// Created by Shaun Harrison on 10/16/08. 
// Copyright 2008 enormego. All rights reserved. 
// 

#import "UIAlertView+Helper.h" 

void UIAlertViewQuick(NSString* title, NSString* message, NSString* dismissButtonTitle) { 
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title 
                message:message 
                delegate:nil 
              cancelButtonTitle:dismissButtonTitle 
              otherButtonTitles:nil 
          ]; 
    [alert show]; 
    [alert autorelease]; 
} 


@implementation UIAlertView (Helper) 

@end 

然後在自己的應用程序 - 使用可達性,當然。例如:

- (void) updateInterfaceWithReachability: (Reachability*) curReach;

UIAlertViewQuick(@"You're offline!", @"Sorry, it looks like you lost your Internet connection. Please reconnect and try again.", @"OK");      

我用這個幫手很多我的應用程序因爲這一切使得它很容易呈現alertView給用戶。

希望它有幫助!