我正在尝试利用ABPersonViewController的简单性,同时稍微定制它的外观以匹配我的应用程序的外观。
我将ABPersonViewController子类化,并使用this technique,循环遍历ABPersonViewController的视图层次结构,这是我的输出:
UIView: 0x5a45d80; frame = (0 0; 320 416); autoresize = W+H; layer = > | ABPersonTableView: 0x6041a00; baseClass = UITableView; frame = (0 0; 320 416); clipsToBounds = YES; autoresize = W+H; layer = ; contentOffset: {0, 0}> | | ABMultiCell: 0x5a50080; baseClass = UITableViewCell; frame = (0 94; 320 45); autoresize = W; tag = 10; layer = > | | | UIGroupTableViewCellBackground: 0x5a678d0; frame = (9 0; 302 45); autoresize = W; layer = > | | | UITableViewCellContentView: 0x5a62670; frame = (10 1; 300 43); layer = > | | | | ABMultiCellContentView_Simple: 0x5a4fef0; frame = (0 0; 300 43); text = '(555) 555-5555'; clipsToBounds = YES; layer = > | | | | | UILabel: 0x5a61590; frame = (5 14.54; 70 16); text = 'mobile'; clipsToBounds = YES; userInteractionEnabled = NO; layer = > | | | | | ABDividerView: 0x5a62ff0; frame = (79 0; 1 44); alpha = 0; layer = > | | | | | | ABSteadfastLineView: 0x5a53ab0; frame = (0 0; 1 44); layer = > | | | | | ABHighlightingTextField: 0x5a53c30; baseClass = UITextField; frame = (85 12; 210 21); text = '(555) 555-5555'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = > | | | | | | UITextFieldLabel: 0x5a53db0; frame = (0 0; 210 19); text = '(530) 305-0835'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = > | | UIView: 0x5a5b300; frame = (0 0; 320 94); layer = > | | | ABPersonTableHeaderView: 0x5a444b0; frame = (0 0; 320 94); clipsToBounds = YES; autoresize = W; layer = > | | | | ABPersonImageView: 0x5a449c0; baseClass = UIControl; frame = (19 15; 64 64); clipsToBounds = YES; autoresize = RM+BM; layer = > | | | | | ABClippingImageView: 0x5a6aae0; frame = (0 0; 64 64); opaque = NO; userInteractionEnabled = NO; layer = > | | | | | ABImageWellLabelView: 0x5a6c0b0; frame = (0 0; 64 64); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = > | | | | ABPersonNameEditingViewContainer: 0x5a4a9e0; frame = (101 15; 530 64); alpha = 0; autoresize = W+BM; layer = > | | | | | ABMultiCellContentView_Name: 0x5a4b480; frame = (1 0; 208 64); clipsToBounds = YES; layer = > | | | | | | ABHighlightingTextField: 0x5a4d7c0; baseClass = UITextField; frame = (-5 12; 10 21); text = 'First Name'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; tag = 1; layer = > | | | | | | | UITextFieldLabel: 0x5a4b3e0; frame = (-10 0; 10 19); text = 'First Name'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = > | | | | | | ABHighlightingTextField: 0x5a50a90; baseClass = UITextField; frame = (-5 56; 10 21); text = 'Last Name'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; tag = 2; layer = > | | | | | | | UITextFieldLabel: 0x5a4e5d0; frame = (-10 0; 10 19); text = 'Last Name'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = > | | | | | | ABDividerView: 0x5a52300; frame = (0 44; 0 1); layer = > | | | | | | | ABSteadfastLineView: 0x5a525d0; frame = (0 0; 0 1); layer = > | | | | | | ABHighlightingTextField: 0x5a52400; baseClass = UITextField; frame = (-5 100; 10 21); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; tag = 3; layer = > | | | | | | | UITextFieldLabel: 0x5a5a4e0; frame = (-8 0; 10 19); text = 'Company'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = > | | | | | | ABDividerView: 0x5a53f00; frame = (0 88; 0 1); layer = > | | | | | | | ABSteadfastLineView: 0x5a53f80; frame = (0 0; 0 1); layer = > | | | | ABPersonNameDisplayView: 0x5a45cf0; baseClass = UIControl; frame = (97 15; 204 64); autoresize = W; layer = > | | | | | UILabel: 0x5a4bbd0; frame = (0 21; 109 23); text = 'First Name Last Name'; clipsToBounds = YES; autoresize = W; userInteractionEnabled = NO; layer = > | | | | | UILabel: 0x5a4c020; frame = (0 0; 204 0); clipsToBounds = YES; autoresize = W; userInteractionEnabled = NO; layer = > | | UIImageView: 0xcc032a0; frame = (0 409; 320 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = > | | UIImageView: 0xcc03350; frame = (313 262; 7 154); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = >
甜!所以我应该能够递归地遍历根UIView的子视图,并改变我心中的内容。
问题是,在执行此循环时,根UIView只显示一个子视图 (ABPersonTableView),我不能再深入了。
任何想法为什么? ABPersonTableView是一个隐藏它创建/包含的所有内容的私有类吗?
我可以通过在递归循环中执行此操作来更改表的背景颜色:
if ([subview isKindOfClass:[UITableView class]]) { ((UITableView *)subview).backgroundColor = [UIColor purpleColor]; }
但是,我无法访问任何UILabel,因为我无法访问ABPersonTableView的任何子视图。
有什么想法吗?
答案 0 :(得分:4)
你被困了,因为Apple只提供两种方式:
ABPersonViewController及其子视图不打算进行修改,因此无法保证在将来的软件更新中使用。
原因是Apple想要一致的外观和感觉。
如果你真的需要匹配你的应用程序的外观和感觉,你将不得不采用上面的方法2)并从头开始重新实现整个事情。这不一定很难,但肯定很耗时。
编辑:请参阅有关海报Q的最终解决方案的评论
答案 1 :(得分:1)
请注意,Apple明确警告不要修改标准用户界面元素的外观和/或操纵标准视图和控件的子视图。如果您只是为自己构建这个,没问题,但如果您计划将此应用程序提交到应用程序商店,请准备拒绝。
同样,这是一个很好的问题。
答案 2 :(得分: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
}
}
答案 3 :(得分:0)
你是否在-viewDidLoad
这样做?您可能必须等到表视图完成后调用内部用作数据源的任何内容来创建其所有单元格。您可以通过调用表上的-reloadData
或等待一个周期(使用-performSelector:withObject:afterDelay:
延迟为0)来执行此操作,然后然后尝试弄乱其单元格内容