0

I have a UINavigationController/UITableView and I want to present a UIView over top of it when the table is empty to give the user a prompt on how to add items to the table.

I've never make a UIView (as opposed to a UIViewController before) so I'll step through what I did to make it:

  1. Make a new UIView Class - MakeSentenceHelperView
  2. Make a nib called MakeSentenceHelperView.xib
  3. Set File's owner to MakeSentenceHelperView

Load the nib in the MakeSentenceHelperView:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSLog(@"makesentencehelperview init");
        [[NSBundle mainBundle] loadNibNamed:@"MakeSentenceHelperView" owner:self options:nil];
    }
    return self;
}

and present the MakeSentenceHelperView in the UITableViewController:

        //present the placeholder view for sentences
        MakeSentenceHelperView *makeSentenceHelperView = [[MakeSentenceHelperView alloc] init];

        NSLog(@"present placeholder: self.navigationcontroller.view: %@", self.navigationController.view);

        //Something like this:
        [self.navigationController.view addSubview:makeSentenceHelperView];
        [self.navigationController.view bringSubviewToFront:makeSentenceHelperView];

The class loads and logs ok, but nothing appears in front of the UITableView - where have I gone wrong?

UPDATE: if I add [self.tableView setHidden:YES]; then the tableview disappears and the space is black and empty. I'm assuming this means I'm setting up the View wrong, somewhere.

glenstorey
  • 5,134
  • 5
  • 39
  • 71
  • On subclassing a UIView with a nib, go through [this link](http://stackoverflow.com/questions/5056219/uiview-and-initwithframe-and-a-nib-file-how-can-i-get-the-nib-file-loaded) – Ilanchezhian Mar 20 '12 at 06:19
  • That's a really helpful link, thank you- I implemented awakeFromNib and the other things they spoke of, but I'm still having the same problem. – glenstorey Mar 20 '12 at 20:56

2 Answers2

0

You can use https://github.com/ecstasy2/toast-notifications-ios/ for showing Toast view liek Android. Check array size and if table view is not showing then called this one and show any custom method.

Mangesh
  • 2,257
  • 4
  • 24
  • 51
0

Thanks to @Aadhira for their link which led me to the problem.

  1. I needed to add awakeFromNib
  2. I was missing [self addSubview:self.view]; at the end of initWithFrame.
glenstorey
  • 5,134
  • 5
  • 39
  • 71