Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当我的表视图为空时显示标签(添加一些数据)?_Ios_Tableview - Fatal编程技术网

Ios 当我的表视图为空时显示标签(添加一些数据)?

Ios 当我的表视图为空时显示标签(添加一些数据)?,ios,tableview,Ios,Tableview,我有一个带有“添加”按钮的表视图。当用户按下“添加”按钮时,我向表视图添加数据,但当表不包含数据时,我希望显示带有消息的标签: 没有添加数据 我使用的是核心数据。我已经尝试了堆栈溢出的一些建议,但没有解决方案 - (void)viewDidLoad{ nomatchesView = [[UIView alloc] initWithFrame:self.view.frame]; nomatchesView.backgroundColor = [UIColor cl

我有一个带有“添加”按钮的表视图。当用户按下“添加”按钮时,我向表视图添加数据,但当表不包含数据时,我希望显示带有消息的标签:

没有添加数据

我使用的是核心数据。我已经尝试了堆栈溢出的一些建议,但没有解决方案

- (void)viewDidLoad{

        nomatchesView = [[UIView alloc] initWithFrame:self.view.frame];
        nomatchesView.backgroundColor = [UIColor clearColor];

        UILabel *matchesLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,320,320)];
        matchesLabel.font = [UIFont boldSystemFontOfSize:18];
        matchesLabel.minimumFontSize = 12.0f;
        matchesLabel.numberOfLines = 1;
        matchesLabel.lineBreakMode = UILineBreakModeWordWrap;
        matchesLabel.shadowColor = [UIColor lightTextColor];
        matchesLabel.textColor = [UIColor darkGrayColor];
        matchesLabel.shadowOffset = CGSizeMake(0, 1);
        matchesLabel.backgroundColor = [UIColor clearColor];
        matchesLabel.textAlignment =  UITextAlignmentCenter;

        //Here is the text for when there are no results
        matchesLabel.text = @"No Matches";


        nomatchesView.hidden = YES;
        [nomatchesView addSubview:matchesLabel];
        [self.tableView insertSubview:nomatchesView belowSubview:self.tableView];
    }



    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        //If there is no table data, unhide the "No  data added" view
        if(catefetchedResultsController == 0 ){
        nomatchesView.hidden = NO;
        } else {
        nomatchesView.hidden = YES;
        }

        return [data count];
    }

提前谢谢

您的视图必须是UITableView的tableFooterView或tableHeaderView:

self.tableView.tableFooterView = noMatchesView

您是使用UITableViewController子类还是将表视图添加到根视图的UIViewController子类?UIViewController子类和uitableview…在这种情况下,我会将标签添加到视图而不是表视图,并隐藏表视图/取消隐藏标签。我使用的另一种方法是,当数组计数=0时,用消息填充表中的一行。这取决于你要找的是什么。请出示一些代码。当用户打开我的应用程序时,如果他们还没有将任何数据添加到表视图中,我是一个非常初学者。标签或图像任何内容都应显示隐藏=否。。在用户添加一些标签或图像应该隐藏的数据后…我需要该标签或图像作为表视图的子视图。因为我不太熟悉该子视图的各个部分。。