我已經在過去這樣做的方式是有其容納任何活動視圖或視圖正確的內容視圖。
在視圖控制器的筆尖,而不是添加到子視圖的主視圖,留空,併爲視圖正確新視圖(如在下面的示例的表圖)。
另外創建活動圖(具有螺紋進度指示器或諸如此類)和一個「無結果」視圖。
//
// ContainerViewController.h
//
#import <UIKit/UIKit.h>
@interface ContainerViewController : UIViewController
{
UIView *myContainerView;
UITableView *myTableView;
UIView *mySearchActivityView;
UIView *myZeroResultsView;
UIView *myCurrentlyShowingView;
}
@property (retain, nonatomic) IBOutlet UIView *containerView;
@property (retain, nonatomic) IBOutlet UITableView *tableView;
@property (retain, nonatomic) IBOutlet UIView *searchActivityView;
@property (retain, nonatomic) IBOutlet UIView *zeroResultsView;
@property (assign) UIView *currentlyShowingView;
@end
//
// ContainerViewController.m
//
#import "ContainerViewController.h"
@implementation ContainerViewController
@synthesize containerView = myContainerView;
@synthesize tableView = myTableView;
@synthesize searchActivityView = mySearchActivityView;
@synthesize zeroResultsView = myZeroResultsView;
- (void)dealloc
{
[myContainerView release], myContainerView = nil;
[myTableView release], myTableView = nil;
[mySearchActivityView release], mySearchActivityView = nil;
[myZeroResultsView release], myZeroResultsView = nil;
myCurrentlyShowingView = nil;
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.currentlyShowingView = mySearchActivityView;
mySearchActivityView.backgroundColor = [UIColor clearColor];
myZeroResultsView.backgroundColor = [UIColor clearColor];
}
- (void)setCurrentlyShowingView:(UIView *)view
{
[myCurrentlyShowingView removeFromSuperview];
CGRect frame = view.frame;
frame.size = myContainerView.frame.size;
view.frame = frame;
[myContainerView addSubview:view];
myCurrentlyShowingView = view;
if (view == myTableView)
[myTableView reloadData];
}
- (UIView *)currentlyShowingView
{
return myCurrentlyShowingView;
}
@end
而且在派生類中的方法-viewDidLoad,掀起了(異步)查詢:
- (void)viewDidLoad
{
[super viewDidLoad];
myQueryLoader = [[QueryLoader alloc] initWithQuery:@"whatever" delegate:self];
self.currentlyShowingView = mySearchActivityView;
}
和
然後從類似下面的派生類控制器在代表回撥:
- (void)queryLoader:(QueryLoader *)queryLoader didEndWithResults:(id)results error:(NSError *)error
{
myItems = [results retain];
if (myItems)
self.currentlyShowingView = myTableView;
else
self.currentlyShowingView = myZeroResultsView;
}
希望這有助於!
這是一個有用的博客文章! http://suavesnippets.blogspot.com/2011/06/animation-effect-on-your-splashwelcome.html – Appster 2011-06-14 14:58:09