How To Replace UITableView With Image?

心已入冬 提交于 2019-12-04 09:01:34

问题


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?


回答1:


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



回答2:


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



回答3:


It's not that difficult to achieve, you just can show the image you want to show with the specified frame (may be frame(0, 44, 320, 392)). and check for the table rows(actually the count of array that u are using to show in table) if it is nonzero just show the image and show the table otherwise.

try this concept and come back with any problem or query..



来源:https://stackoverflow.com/questions/5400342/how-to-replace-uitableview-with-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!