0
我有一个表视图与添加按钮。当添加按钮,用户按下我将数据添加到表视图,但我当表不包含任何数据我想显示一个消息的标签:当我的表格视图为空时显示标签(添加一些数据)?
没有数据添加
我使用核心数据。我已经尝试了Stack Overflow的一些建议,但没有解决方案的帮助。
- (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];
}
在此先感谢!
您是否使用了'UITableViewController'子类或'UIViewController'子类与表视图添加到根的看法? – Paulw11
UIViewController子类用的UITableView ... – david
在这种情况下,我将标签添加到视图,而不是的tableview和隐藏表视图/取消隐藏的标签。我使用的另一种方法是在数组== 0时用消息填充表中的单个行。这取决于你在寻找什么 – Paulw11