3

我试图利用 ABPersonViewController 的简单性,同时稍微定制它的外观以匹配我的应用程序的外观和感觉。

我将 ABPersonViewController 子类化,并使用这种技术,循环遍历 ABPersonViewController 的视图层次结构,这是我的输出:

UIView:0x5a45d80;帧 = (0 0; 320 416); 自动调整大小 = W+H;层=>
   | ABPersonTableView: 0x6041a00; 基类 = UITableView; 帧 = (0 0; 320 416); clipsToBounds = YES; 自动调整大小 = W+H;层 = ; 内容偏移:{0, 0}>
   | | ABMultiCell:0x5a50080;基类 = UITableViewCell; 帧 = (0 94; 320 45); 自动调整大小 = W;标签 = 10; 层=>
   | | | UIGroupTableViewCellBackground: 0x5a678d0; 帧 = (9 0; 302 45); 自动调整大小 = W;层=>
   | | | UITableViewCellContentView: 0x5a62670; 帧 = (10 1; 300 43); 层=>
   | | | | ABMultiCellContentView_Simple:0x5a4fef0;帧 = (0 0; 300 43); 文字='(555)555-5555';clipsToBounds = YES; 层=>
   | | | | | UILabel: 0x5a61590; 帧 = (5 14.54; 70 16); 文字='手机'; clipsToBounds = YES; 用户交互启用 = 否;层=>
   | | | | | ABDividerView:0x5a62ff0;帧 = (79 0; 1 44); 阿尔法 = 0; 层=>
   | | | | | | ABSteadfastLineView: 0x5a53ab0; 帧 = (0 0; 1 44); 层=>
   | | | | | ABHighlightingTextField:0x5a53c30;基类 = UITextField; 帧 = (85 12; 210 21); 文字='(555)555-5555';clipsToBounds = YES; 不透明=否;用户交互启用 = 否;层=>
   | | | | | | UITextFieldLabel: 0x5a53db0; 帧 = (0 0; 210 19); 文字='(530)305-0835';clipsToBounds = YES; 不透明=否;用户交互启用 = 否;层=>
   | | UIView:0x5a5b300;帧 = (0 0; 320 94); 层=>
   | | | ABPersonTableHeaderView: 0x5a444b0; 帧 = (0 0; 320 94); clipsToBounds = YES; 自动调整大小 = W;层=>
   | | | | ABPersonImageView:0x5a449c0;基类 = UIControl; 帧 = (19 15; 64 64); clipsToBounds = YES; 自动调整大小 = RM+BM;层=>
   | | | | | ABClippingImageView: 0x5a6aae0; 帧 = (0 0; 64 64); 不透明=否;用户交互启用 = 否;层=>
   | | | | | ABImageWellLabelView: 0x5a6c0b0; 帧 = (0 0; 64 64); 阿尔法 = 0; 不透明=否;用户交互启用 = 否;层=>
   | | | | ABPersonNameEditingViewContainer: 0x5a4a9e0; 帧 = (101 15; 530 64); 阿尔法 = 0; 自动调整大小 = W+BM;层=>
   | | | | | ABMultiCellContentView_Name:0x5a4b480;帧 = (1 0; 208 64); clipsToBounds = YES; 层=>
   | | | | | | ABHighlightingTextField:0x5a4d7c0;基类 = UITextField; 帧 = (-5 12; 10 21); 文本 = '名字'; clipsToBounds = YES; 不透明=否;用户交互启用 = 否;标签 = 1; 层=>
   | | | | | | | UITextFieldLabel: 0x5a4b3e0; 帧 = (-10 0; 10 19); 文本 = '名字'; clipsToBounds = YES; 不透明=否;用户交互启用 = 否;层=>
   | | | | | | ABHighlightingTextField:0x5a50a90;基类 = UITextField; 帧 = (-5 56; 10 21); text = '姓氏'; clipsToBounds = YES; 不透明=否;用户交互启用 = 否;标签 = 2; 层=>
   | | | | | | | UITextFieldLabel: 0x5a4e5d0; 帧 = (-10 0; 10 19); text = '姓氏'; clipsToBounds = YES; 不透明=否;用户交互启用 = 否;层=>
   | | | | | | ABDividerView:0x5a52300;帧 = (0 44; 0 1); 层=>
   | | | | | | | ABSteadfastLineView: 0x5a525d0; 帧 = (0 0; 0 1); 层=>
   | | | | | | ABHighlightingTextField:0x5a52400;基类 = UITextField; 帧 = (-5 100; 10 21); clipsToBounds = YES; 不透明=否;用户交互启用 = 否;标签 = 3; 层=>
   | | | | | | | UITextFieldLabel: 0x5a5a4e0; 帧 = (-8 0; 10 19); 文本 = '公司'; clipsToBounds = YES; 不透明=否;用户交互启用 = 否;层=>
   | | | | | | ABDividerView:0x5a53f00;帧 = (0 88; 0 1); 层=>
   | | | | | | | ABSteadfastLineView: 0x5a53f80; 帧 = (0 0; 0 1); 层=>
   | | | | ABPersonNameDisplayView: 0x5a45cf0; 基类 = UIControl; 帧 = (97 15; 204 64); 自动调整大小 = W;层=>
   | | | | | UILabel: 0x5a4bbd0; 帧 = (0 21; 109 23); text = '名字姓氏'; clipsToBounds = YES; 自动调整大小 = W;用户交互启用 = 否;层=>
   | | | | | UILabel: 0x5a4c020; 帧 = (0 0; 204 0); clipsToBounds = YES; 自动调整大小 = W;用户交互启用 = 否;层=>
   | | UIImageView:0xcc032a0;帧 = (0 409; 320 7); 阿尔法 = 0; 不透明=否;自动调整大小 = TM;用户交互启用 = 否;层=>
   | | UIImageView: 0xcc03350; 帧 = (313 262; 7 154); 阿尔法 = 0; 不透明=否;自动调整大小 = LM; 用户交互启用 = 否;层=>

甜的!所以我应该能够通过根 UIView 的子视图递归循环,并改变我的内心内容。

问题是,当执行这个循环时,根 UIView 只显示一个子视图(ABPersonTableView),我不能再深入了。

任何想法为什么?ABPersonTableView 是隐藏它创建/包含的所有内容的私有类吗?

我可以通过在递归循环中执行此操作来更改表格的背景颜色:

if ([subview isKindOfClass:[UITableView class]]) {
    ((UITableView *)subview).backgroundColor = [UIColor PurpleColor];
}

但是,我无法访问任何 UILabel,因为我无法访问 ABPersonTableView 的任何子视图。

有任何想法吗?

4

4 回答 4

4

你被卡住了,因为 Apple 只提供了两种方法:

  1. Apple 内置的、自动的、超级简单的外观和感觉方式(不可定制)
  2. 使用对 AddressBook 的低级别调用,您可以自己动手做所有事情

ABPersonViewController 及其子视图并不意味着要被修改,并且不保证这样做可以与未来的软件更新一起使用。

原因是苹果想要一致的外观和感觉。

如果你真的需要匹配你的应用程序的外观和感觉,你将不得不使用上面的方法 2) 并从头开始重新实现整个事情。这不一定很难,但肯定很耗时。

编辑:请参阅评论以获取海报 Q 的最终解决方案

于 2011-03-16T17:53:29.060 回答
1

请注意,Apple 明确警告不要修改标准用户界面元素的外观和/或操纵标准视图和控件的子视图。如果您只是为自己构建它,没问题,但如果您打算将此应用程序提交到应用商店,请准备好被拒绝。

不管怎样,这是一个很好的问题。

于 2011-03-16T20:41:05.507 回答
1

调用 layoutSubViews 后,您可以在 viewDidLoad 中访问 ABPersonTableView :) 示例:

- (void)viewDidLoad
{
  [super viewDidLoad];

  // get ABPersonTableView and forced it layout subviews
  UIView *personTableView = [self.view.subviews objectAtIndex:0];
  [personTableView layoutSubviews];

  // loop through subviews and customize all exceps contacts image
  NSArray *subViews = personTableView.subviews;
  UIView *view;
  for(int i = 0; i < subViews.count-1; i++) {
    view = [subViews objectAtIndex:i];
    //...customize cells
  }    
}
于 2012-11-17T05:45:48.230 回答
0

你在做这个-viewDidLoad吗?您可能必须等到表格视图完成调用它内部用作数据源的任何内容来创建其所有单元格。你可以通过调用-reloadData表来做到这一点,或者等待一个周期(使用-performSelector:withObject:afterDelay:延迟为 0),然后尝试弄乱它的单元格内容。

于 2011-03-16T17:54:18.303 回答