Sheehan Alam
Sheehan Alam

Reputation: 60899

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 instead of the UITableView. How can I do this? I need to be able to bring the UITableView back also.

Upvotes: 1

Views: 3515

Answers (5)

Akshay
Akshay

Reputation: 5765

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

Upvotes: 9

Dimple
Dimple

Reputation: 406

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

Upvotes: 0

Dylan Reich
Dylan Reich

Reputation: 1430

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;

Upvotes: 0

ohho
ohho

Reputation: 51941

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;
}

Upvotes: 2

Louie
Louie

Reputation: 5940

How about..

if(myBOOL == YES) {

   ADifferentViewController * vc = (ADifferentViewController *)[[ADifferentViewController alloc]init];
   [self.navigationController pushViewController:vc animated:NO];
   [vc release];

}

Upvotes: 0

Related Questions