2015-10-15 63 views
0

我正在使用MSCellAccessory將自定義顏色設置爲accessoryView。它運行良好。但是,當我將按鈕放在單元格中並單擊單元格時,複選標記是可見的,但它與刪除按鈕重疊。檢查我的快照。 In this image I set border to accessory view. It appear on delete. So I cannot press delete button.UITableViewCell accessoryView重疊單元格自定義按鈕或如何更改accessoryView位置?

那麼如何在UITableViewCell中更改單元accessoryView的位置或設置accessoryView下面的刪除按鈕。

+0

製作自己的UITableViewCell子類 – ColdSteel

回答

0
If you are sub-classing the UITableViewCell you can adjust it in layoutSubviews 

- (void)layoutSubviews { 
    [super layoutSubviews]; 

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

OTHERWISE...... 
Add subview instead of 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]; 
0

我解決了通過添加UIImageView剔。並放在刪除按鈕旁邊,它適用於我。我不使用表格單元附件。請檢查下面的代碼。

- (UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier 
{ 
CGRect cellRectangle = CGRectMake(0, 0, CGRectGetWidth(tableViewSavedSearch.frame), tableViewSavedSearch.rowHeight); 
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 
cell.frame = cellRectangle; 
CGFloat imageWidth = 30; 

//Name 
UILabel *lblName = [DesignModel createPaddingLabel:CGRectMake(0, 0, CGRectGetWidth(cellRectangle) - (imageWidth * 2), tableViewSavedSearch.rowHeight) labelTag:TAG_SAVED_SEARCH_NAME textColor:COLOUR_BLUE_DARK textAlignment:NSTextAlignmentLeft textFont:[UIFont fontWithName:FONT_CENTURY_GOTHIC size:14] padding:UIEdgeInsetsMake(0, 5, 0, 5)]; 
[cell.contentView addSubview:lblName]; 

//Delete button 
UIButton *button = [DesignModel createImageButton:CGRectMake(CGRectGetMaxX(lblName.frame), 0, imageWidth, tableViewSavedSearch.rowHeight) image:imageDelete tag:TAG_SAVED_SEARCH_DALETE]; 
[button addTarget:self action:@selector(btnSaveAndSearch_DeleteAction:) forControlEvents:UIControlEventTouchUpInside]; 
[cell.contentView addSubview:button]; 

//TICK 
UIImageView *imageView = [DesignModel createImageView:CGRectMake(CGRectGetMaxX(button.frame), 0, imageWidth, tableViewSavedSearch.rowHeight) image:imageTick tag:TAG_SAVED_SEARCH_TICK contentMode:UIViewContentModeCenter]; 
[cell.contentView addSubview:imageView]; 

return cell; 
} 
相關問題