Ios 如何最初隐藏UITableview页脚视图?
我需要在数组为空时以“无通知”的形式显示消息,但一旦数组包含数据,则删除页脚视图并在tableview中显示数据Ios 如何最初隐藏UITableview页脚视图?,ios,uitableview,Ios,Uitableview,我需要在数组为空时以“无通知”的形式显示消息,但一旦数组包含数据,则删除页脚视图并在tableview中显示数据 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection: (NSInteger)section { if(self.notificationDataArray.count == 0){ self.tableView.tableFooterView.hidden = NO; ret
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection: (NSInteger)section
{
if(self.notificationDataArray.count == 0){
self.tableView.tableFooterView.hidden = NO;
return 50;
} else {
return 0;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(self.notificationDataArray.count == 0){
UIView *view = [[UIView alloc]init];
view.frame = CGRectMake(0, 0, self.view.frame.size.width, [self tableView:tableView heightForFooterInSection:section]);
UILabel *textLabel = [[UILabel alloc]initWithFrame:view.frame];
[view addSubview:textLabel];
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.textColor = [UIColor blueTextColor];
textLabel.font = [UIFont boldSystemFontOfSize:16.0];
textLabel.text = @"No Notification";
return view;
} else {
return nil;
}
}
但最初在API调用之前,数组将为空,因此页脚视图会出现几秒钟,然后消失。如何最初隐藏页脚视图,我的意思是在加载tableview之前。有人能为我建议一个解决方案吗,
谢谢你
除此之外,您还可以在数组计数为零时隐藏tableview,也可以在viewdidLoad方法中最初隐藏页脚
除此之外,您还可以在数组计数为零时隐藏tableview,也可以在viewdidLoad方法中最初隐藏页脚。为什么不使用BOOL实例变量来指示数据的加载
BOOL dataLoaded;
在viewDidLoad
中初始化,将其设置为NO
。加载数据后,您可以将其设置为“是”
dataLoaded = YES
现在检查条件是
if(self.notificationDataArray.count == 0 && dataLoaded){
// Do your stuff
}
为什么不使用BOOL实例变量来指示数据的加载
BOOL dataLoaded;
在viewDidLoad
中初始化,将其设置为NO
。加载数据后,您可以将其设置为“是”
dataLoaded = YES
现在检查条件是
if(self.notificationDataArray.count == 0 && dataLoaded){
// Do your stuff
}
不要返回nil,而是用0帧初始化一个空白视图并返回该帧
if(self.notificationDataArray.count == 0){
UIView *view = [[UIView alloc]init];
view.frame = CGRectMake(0, 0, self.view.frame.size.width, [self tableView:tableView heightForFooterInSection:section]);
UILabel *textLabel = [[UILabel alloc]initWithFrame:view.frame];
[view addSubview:textLabel];
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.textColor = [UIColor blueTextColor];
textLabel.font = [UIFont boldSystemFontOfSize:16.0];
textLabel.text = @"No Notification";
return view;
} else {
UIView *view = [[UIView alloc]init];
view.frame = CGRectMake(0, 0, 0, 0);
return view ;
}
不要返回nil,而是用0帧初始化一个空白视图并返回该帧
if(self.notificationDataArray.count == 0){
UIView *view = [[UIView alloc]init];
view.frame = CGRectMake(0, 0, self.view.frame.size.width, [self tableView:tableView heightForFooterInSection:section]);
UILabel *textLabel = [[UILabel alloc]initWithFrame:view.frame];
[view addSubview:textLabel];
textLabel.textAlignment = NSTextAlignmentCenter;
textLabel.textColor = [UIColor blueTextColor];
textLabel.font = [UIFont boldSystemFontOfSize:16.0];
textLabel.text = @"No Notification";
return view;
} else {
UIView *view = [[UIView alloc]init];
view.frame = CGRectMake(0, 0, 0, 0);
return view ;
}
在视图中,在Api调用之前,您确实这样做了
yourTableView.sectionFooterHeight = 0;
[[yourTableView tableFooterView] setHidden:YES];
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if ([yourArray count]==0) {
return nil;
}
return yourCustomView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if ([yourArray count]==0) {
return 0;
}
return yourCustomViewHeight;
}
然后在得到响应后,您可以显示页脚视图,根据需要更改值在加载视图时,您可以在Api调用之前这样做
yourTableView.sectionFooterHeight = 0;
[[yourTableView tableFooterView] setHidden:YES];
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if ([yourArray count]==0) {
return nil;
}
return yourCustomView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
if ([yourArray count]==0) {
return 0;
}
return yourCustomViewHeight;
}
然后在得到响应后,您可以显示页脚视图,根据需要更改值我只是在titleForFooterInstitution中设置了文本。如果项目计数为0,则为空。 加载表格时,不会显示文本 -(NSString*)表格视图:(UITableView*)表格视图标题页脚分类:(NSInteger)部分{
NSString *mensaje = @"";
NSInteger numberOfRowsInSection = [self tableView:self.tableView numberOfRowsInSection:section ];
if (numberOfRowsInSection == 0) {
mensaje = @"No notifications";
}
return mensaje;
}我刚刚在titleForFooterInstitution中设置了文本。如果项目计数为0,则为空。 加载表格时,不会显示文本 -(NSString*)表格视图:(UITableView*)表格视图标题页脚分类:(NSInteger)部分{
NSString *mensaje = @"";
NSInteger numberOfRowsInSection = [self tableView:self.tableView numberOfRowsInSection:section ];
if (numberOfRowsInSection == 0) {
mensaje = @"No notifications";
}
return mensaje;
}在videDidLoad中隐藏它?-(void)viewDidLoad{[super viewDidLoad];self.tableView.tableFooterView.hidden=YES;}..我尝试了这个方法,但没有成功,它又出现了一小部分秒为什么不只是在有数据之前隐藏整个tableView?我尝试了上面的方法,但是当tableview隐藏时,屏幕看起来是黑色的…..如果屏幕看起来是黑色的,则表示没有推送视图,因此您需要将视图背景颜色更改为白色不清晰颜色隐藏在videDidLoad?-(void)viewDidLoad{[super viewDidLoad];self.tableview.tableFooterView.hidden=YES;}..我尝试了这个,但没有成功,它又出现了几秒钟为什么不在你有数据之前隐藏整个tableView?我试过上面的方法,但是当tableview隐藏时,屏幕看起来是黑色的…..如果屏幕看起来是黑色的,则表示没有推送视图,因此您需要将视图背景颜色更改为白色不清晰颜色上面的代码最初不会隐藏页脚视图,并且在viewDidload中隐藏页脚视图对我也不起作用..上面的代码最初不会隐藏页脚视图,在viewDidload中隐藏页脚视图也不适合我。。