我有一個UITableView,如果存在活動的網絡連接,它將獲取數據填充。當沒有連接時,我想添加一個視圖到當前的視圖,它會顯示沒有Internet連接。與沒有同步照片時的照片應用類似。我不知道我該如何做到這一點。如何添加UITableView的subview ontop?
1
A
回答
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給用戶。
希望它有幫助!
相關問題
- 1. 如何正確添加Subview到NSSrollView?
- 2. 我應該如何添加Subview到cell.contentView?
- 3. UITableview cell subview larger height then cell
- 4. 在主視圖中添加subview在UISplitView
- 5. UITableView subview出現在單元格
- 6. 添加Sharepoint 2007/2010 ontop of TFS 2010
- 7. 如何使用UISilder在SubView中添加和刪除UIButtons?
- 8. 如何添加的TabBar到的UITableView
- 9. 如何在iOS8的UIAlertController中添加UITableview?
- 10. 添加到UITableView
- 11. 如何成爲OnTop而不是OnTop的全屏應用程序
- 12. 如何將UITableView添加到UIAlertView?
- 13. 如何將部分添加到UITableView?
- 14. 如何將UITextView添加到UITableView細節
- 15. 如何在UITableVIew下添加UIButton?
- 16. 如何添加項目到UITableView?
- 17. 如何在uitableview中添加導航欄
- 18. 如何將UITableView添加到UIView中?
- 19. 如何將陰影添加到UITableView?
- 20. 如何將對象添加到UITableView中?
- 21. 如何在UITableView中添加節標題
- 22. 如何添加單元格到UITableView?
- 23. 如何將單元添加到UITableView?
- 24. 如何在uitableview上添加菜單
- 25. 如何爲UITableView添加自定義EditingAccessoryView?
- 26. 如何將描述添加到UITableView
- 27. 如何將細胞添加到uitableview
- 28. 如何動態添加行到UITableView?
- 29. 如何在UIViewController中添加多個UITableView?
- 30. 如何在uitableview中添加搜索欄?