iOS 7以不同的方式列出accessoryView和accessoryType?

时间:2013-09-25 21:56:53

标签: ios ios7 uitableview

其他人都注意到iOS 7以与内置accessoryTypes不同的方式布置自定义accessoryViews?

像这样:

enter image description here

最上面的一个是使用:

完成的
cell.accessoryView = cell.accessoryButton;

(其中accessoryButton是一个自定义的UIButton),而第二个是使用:

完成的
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

相同的代码,相同的应用程序,相同的Xcode,但在iOS 6上运行:

enter image description here

这是SDK中的错误吗?或者我可以通过代码控制的东西?

2 个答案:

答案 0 :(得分:23)

如果您对UITableViewCell进行细分,则可以在layoutSubviews

中对其进行调整
- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect accessoryViewFrame = self.accessoryView.frame;
    accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame);
    self.accessoryView.frame = accessoryViewFrame;
}

答案 1 :(得分:0)

添加子视图而不是accessoryView

UIButton *indicatorBtn = [UIButton  buttonWithType:UIButtonTypeCustom];
indicatorBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50);
[indicatorBtn setBackgroundImage:[UIImage imageNamed:@"right_indicator.png"] 
                     forState:UIControlStateNormal];
indicatorBtn.backgroundColor = [UIColor clearColor];
//indicatorBtn.alpha = 0.5;
indicatorBtn.tag = indexPath.row;
[indicatorBtnaddTarget:self action:@selector(method:) 
    forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:indicatorBtn];