How can I show an empty view in place of a UITableView?
I have a UITableViewController. When a certain BOOL is set, I want to show another view instea开发者_Python百科d of the UITableView. How can I do this? I need to be able to bring the UITableView back also.
I implemented the following method in my Table view controller subclass to reload its background.
- (void)reloadBackground
{
if(myBool)
{
//load the view to be displayed from a nib
NSArray* nibs = [[NSBundle mainBundle] loadNibNamed:@"EmptyView" owner:self options:nil];
UIView* emptyView = [nibs objectAtIndex:0];
self.tableView.backgroundView = emptyView;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
else
{
self.tableView.backgroundView = nil;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
}
}
HTH,
Akshay
Instead of a UITableViewController
, you can put two views inside a UIViewController
:
@interface MyViewController : UIViewController <UITableViewDelegate> {
UITableView *tableView;
UIWebView *anotherView;
}
...
if (someBool) {
tableView.hidden = YES;
anotherView.hidden = NO;
} else {
tableView.hidden = NO;
anotherView.hidden = YES;
}
How about..
if(myBOOL == YES) {
ADifferentViewController * vc = (ADifferentViewController *)[[ADifferentViewController alloc]init];
[self.navigationController pushViewController:vc animated:NO];
[vc release];
}
Possibly something like:
if (myBool == YES) {
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:myView];
}
Now to get rid of it:
[myView removeFromSuperview];
Of course there are plenty of other methods...
Even: self.view = myView;
Use a UIView instead if UITableViewController.... from .h file change UITableViewController to UIViewController Connect view to Files owner from xib
take UITableView in a UIView... take another UIView for a blank view and set its background color as Tableview color
If your bool if true then show tableview and hide blank View else hide tableview show blank view
精彩评论