2013-09-25 99 views
9

Bất kỳ ai khác nhận thấy rằng iOS 7 đưa ra các phụ kiện tùy chỉnh khác với các phụ kiện kèm theo?iOS 7 đưa ra phụ kiệnXem và phụ kiệnLoại khác nhau?

Như thế này:

enter image description here

Một đầu được thực hiện sử dụng:

cell.accessoryView = cell.accessoryButton; 

(nơi accessoryButton là một UIButton tùy chỉnh) trong khi cái thứ hai được thực hiện sử dụng:

cell.accessoryView = nil; 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

Cùng một mã, cùng một ứng dụng, cùng một Xcode nhưng chạy trên iOS 6 ở thay đổi:

enter image description here

Đây có phải là lỗi trong SDK không? Hoặc một cái gì đó tôi có thể kiểm soát thông qua mã?

+0

Hiện đã có một số thay đổi như những tác phẩm như thế nào autolayout, nhìn vào tài liệu để chuyển sang ios7. (cba để tìm liên kết xin lỗi) –

Trả lời

23

Nếu bạn đang phụ classing các UITableViewCell bạn có thể điều chỉnh nó trong layoutSubviews

- (void)layoutSubviews { 
    [super layoutSubviews]; 

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

Và nếu bạn không phân lớp ô? – therealjohn

+2

Không còn hoạt động trong iOS 8 nữa? Tất cả các giá trị của 'accessoryViewFrame.size' và' accessoryViewFrame.origin' bằng 0. – JonSlowCN

+0

Có, từ iOS8 và iOS9 khung accessoryView là "(CGRect) _accessoryFrame = (origin = (x = 0, y = 0), size = (chiều rộng = 0, chiều cao = 0)) " –

0

Thêm subview thay vì 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];