Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Replace UITableView With Image?

I have a UITableView that is blank be default until the user edits and adds data to it. I want to show an image with instructions that is shown until the user edits it.

The size of the picture is so it fits under perfectly between the nav bar and the tab bar.

Is there a way to do this programmatically?


2 Answers

you can use removeFromSuperview to remove UITableView from super view then add your UIImageView.

Use the below code :

-(void) NeedView:(BOOL) aIsImageView
{
    if(aIsImageView)
    {
        [m_TableView removeFromSuperview];
        [self.view addSubviews:m_ImageView];
    }
    else 
    {
        [m_ImageView removeFromSuperview];
        [self.view addSubviews:m_TableView];
    }
}
like image 86
Jhaliya - Praveen Sharma Avatar answered Dec 02 '25 03:12

Jhaliya - Praveen Sharma


Create a UIView add your UITableView as a subview. Create a UIImageView with your instructions image and add it as a subView as well. Position the instructions imageView behind the the tableView. In ViewWillAppear add a test for empty table and hide the table based on that check. If you allow users to delete rows you will also have to check for empty table in:

- (void)tableView:(UITableView *)tableView
    commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
    forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
        // do delete
        // get count of rows in UITableView and hide table if it's empty
    }
...
like image 33
Kirby Todd Avatar answered Dec 02 '25 03:12

Kirby Todd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!