1

这涉及 iPhoneOS-sdk-3.2

我很难更改分组 UITableView 的边框颜色。我现在可以很容易地更改单元格背景颜色、分隔符颜色、文本颜色,并且圆角剪辑正确,即使用我选择的任何颜色突出显示也是如此。然而,尽管进行了许多不同的尝试,但周围的边界仍然是灰蒙蒙的。

我已经阅读了我可以通过 Google 找到的所有相关帖子,更不用说 stackoverflow。我已经看到 Mike Akers 针对 UITableViewCell 裁剪的英勇 PITA 解决方案——这个问题在 iPhoneOS 3.0 中得到了解决,但它对我的边框没有帮助。

我已经尝试过编程和基于 xib 的解决方案,并且都提供了相同的结果。

我将在下面分享程序化版本:

我有一个 UIViewController 子类而不是 UITableViewController 子类来充当 UITableView 委托——我在 iPad 上编码时选择了这条路线,据报道 UITableViewController 接管了整个屏幕。我的 UIViewController 子类的 loadView 方法:

- (void) loadView {
  self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  [self.view release];
  self.view.backgroundColor = [UIColor blackColor];

  // add and configure UITableView                                                                                     
  CGRect tableViewRect = CGRectMake(0., 0., 256., 768.);

  myTableView = [[UITableView alloc] initWithFrame:tableViewRect style:UITableViewStyleGrouped];

  // set the tableview delegate to this object and the datasource to the datasource which has already been set          
  myTableView.delegate = self;
  myTableView.dataSource = self;

  myTableView.sectionIndexMinimumDisplayRowCount = 1;

  myTableView.backgroundColor = [UIColor clearColor];
  myTableView.separatorColor = [UIColor whiteColor];
  myTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

  myTableView.opaque = NO;

  // add the table view to our background view                                                                          
  [self.view addSubview:myTableView];
  [myTableView release];
}
4

1 回答 1

5

我找到了解决方案。这种行为似乎是 iPhoneOS 3.2 特有的,因为 Apple 在 iPhoneOS 3.2 中为 UITableView 添加了 backgroundView 属性。

我试过 [myTableView.backgroundView removeFromSuperView] 和 UITableView 只是用另一个替换它。

相反,我的解决方案是添加:

myTableView.backgroundView.hidden = YES;

于 2010-04-11T07:38:26.203 回答