Ios Headerin区的高度没有被呼叫?
我想更改Ios Headerin区的高度没有被呼叫?,ios,uitableview,Ios,Uitableview,我想更改表格标题高度、字体等 我实现了UITableViewDelegate,UITableViewDataSource,并添加了heightForHeaderInSection和viewForHeaderInSection。但这两种方法没有被调用。其他方法,如numberOfRowsInSection/cellforrowatinexpath工作正常。我可以看到表格,但没有标题:( 有什么想法吗 代码如下: - (NSInteger)tableView:(UITableView *)table
表格标题
高度、字体等
我实现了UITableViewDelegate
,UITableViewDataSource
,并添加了heightForHeaderInSection
和viewForHeaderInSection
。但这两种方法没有被调用。其他方法,如numberOfRowsInSection
/cellforrowatinexpath
工作正常。我可以看到表格,但没有标题:(
有什么想法吗
代码如下:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.poHeader.itemList count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"numberOfSectionsInTableView");
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
NSLog(@"*******height");
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSLog(@"***in viewForHeader In section");
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(2, 166, 300.0, 44.0)];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor blackColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont systemFontOfSize:13];
headerLabel.frame = CGRectMake(2, 166, 300.0, 44.0);
headerLabel.text = @"Part No. Description Ext Cost"; // i.e. array element
[customView addSubview:headerLabel];
return customView;
}
差不多一年后,但我想您只设置了数据源,而没有设置委托 您的控制器中必须有如下内容:
myTableview.delegate = self;
myTableview.dataSource = self;
您提到正在调用numberOfRowsInSection/cellForRowAtIndexPath。除了设置委托,这两个函数都属于
UITableViewDataSource
,而不属于swift的UITableViewDelegate
为有问题的类或扩展声明UITableViewDelegate一致性即使调用了委托方法,标题标签也会出现在错误的位置(过低)。由于它是customView的子视图,所以它的来源可能应该是0,0,而不是2166。大约2年后,这应该被检查为已接受,因为它是正确的。我不知道为什么,但即使表视图作为委托和数据源连接到视图控制器,委托连接不知何故被断开。无法a但是这个答案给了我一个解决问题的方法。