我制作了一个 tableView,它在段按钮更改时加载数据。它运行良好。我已将 tableView 背景颜色设置为一些 RGB 值并在其上应用自定义标题。我的代码如下:-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BestFCell *bfcell=(BestFCell*)[tableView dequeueReusableCellWithIdentifier:@"bestfcellIdentifier"];
if (bfcell==nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"BestFCell" owner:self options:nil];
for (id temp in topLevelObjects) {
if ([temp isKindOfClass:[BestFCell class]]) {
bfcell=(BestFCell*)temp;
}
}
}
if (segmentCntr.selectedSegmentIndex==0) {
bfcell.bestsize.text=[[[bestfiveArray objectAtIndex:indexPath.row] valueForKey:[NSString stringWithFormat:@"bestbuysize%i",indexPath.row+1]] valueForKey:@"text"];
bfcell.bestprice.text=[[[bestfiveArray objectAtIndex:indexPath.row] valueForKey:[NSString stringWithFormat:@"bestbuyprice%i",indexPath.row+1]] valueForKey:@"text"];
}else{
bfcell.bestsize.text=[[[bestfiveArray objectAtIndex:indexPath.row] valueForKey:[NSString stringWithFormat:@"bestsellsize%i",indexPath.row+1]] valueForKey:@"text"];
bfcell.bestprice.text=[[[bestfiveArray objectAtIndex:indexPath.row] valueForKey:[NSString stringWithFormat:@"bestsellprice%i",indexPath.row+1]] valueForKey:@"text"];
}
return bfcell;
}
//表格自定义标题视图。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
BestFCell *bfcell=(BestFCell*)[tableView dequeueReusableCellWithIdentifier:@"bestfcellIdentifier"];
if (bfcell==nil) {
NSArray *topLevelObjects=[[NSBundle mainBundle] loadNibNamed:@"BestFCell" owner:self options:nil];
for (id temp in topLevelObjects) {
if ([temp isKindOfClass:[BestFCell class]]) {
bfcell=(BestFCell*)temp;
}
}
}
bfcell.bestsize.text=@"Best Buy Size";
bfcell.bestprice.text=@"Best Buy Price";
bfcell.bestsize.font=[UIFont systemFontOfSize:14.0f];
bfcell.bestprice.font=[UIFont systemFontOfSize:14.0f];
return bfcell;
}
并将页脚设置为零
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] init];
return view;
}
一切都很好,但是为什么在获取横向模式时会出现白线。我的屏幕截图如下:-纵向
在横向模式下
谢谢 !..