2013-01-17 126 views
0

我已經實現了我的自定義單元格以這樣的方式刪除風格

@implementation StandardCellWithImage: UITableViewCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Base-List"]]; 

    _checkbox = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 24, 24)]; 
    _checkbox.userInteractionEnabled = YES; 
    [self addSubview:_checkbox]; 

    /*textField with image/file name*/ 
    _nameLabel = [[UITextField alloc] initWithFrame:CGRectMake(50, 10, 180, 44)]; 
    [_nameLabel setBackgroundColor:[UIColor clearColor]]; 
    [_nameLabel setFont:[UIFont fontWithName:@"HelveticaNeueCE-Bold" size:18.0f]]; 
    [_nameLabel setUserInteractionEnabled:NO]; 
    _nameLabel.keyboardType = UIKeyboardTypeAlphabet; 
    _nameLabel.returnKeyType = UIReturnKeyDone; 
    [self addSubview:_nameLabel]; 
} 
return self; 
} 

我用這的tableView。問題是,當我交換單元格刪除時,在左側只出現紅色減號,但單元格沒有向右移動。它看起來像下面的圖像:

enter image description here

我怎樣才能解決這個問題,我的自定義單元格右移?

回答

2

,你需要在你的代碼只是LITTEL變化

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Base-List"]]; 

    _checkbox = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 24, 24)]; 
    _checkbox.userInteractionEnabled = YES; 

    [self.contentView addSubview:_checkbox]];//also change here 

    // [self addSubview:_checkbox]; 

    /*textField with image/file name*/ 
    _nameLabel = [[UITextField alloc] initWithFrame:CGRectMake(50, 10, 180, 44)]; 
    [_nameLabel setBackgroundColor:[UIColor clearColor]]; 
    [_nameLabel setFont:[UIFont fontWithName:@"HelveticaNeueCE-Bold" size:18.0f]]; 
    [_nameLabel setUserInteractionEnabled:NO]; 
    _nameLabel.keyboardType = UIKeyboardTypeAlphabet; 
    _nameLabel.returnKeyType = UIReturnKeyDone; 
    // [self addSubview:_nameLabel]; 


// i just did change at one line now test your code 
    [self.contentView addSubview:_nameLabel]; 

} 
return self; 
} 

我不使用[self.contentView addSubview:_nameLabel];和做工精細,如: -

我UITableIVew: -

enter image description here

雖然編輯: -

enter image description here

+0

它真的很棒!你已經解決了我的問題,再次感謝。 – edzio27

1

autoresizingMask置於您的UITableViewCell Label。像

_nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; 
+0

謝謝,它幫助我定義列表中的哪個元素應該移位! – edzio27

+0

歡迎@ edzio27 :) – arthankamal