10

これは私の頭をやっています:-)

UITableView内部に完全に機能する CoreData PopulatedがUIViewControllerあり、「スワイプして削除するオプション」を正常に実装しました (これは簡単です)。また、赤い円が表示される編集ボタンで単一のインスタンスを削除することもできます。

私の問題は、CustomCell があるためだと思います。編集ボタンを押してUILabelsも右に移動しません。

私は-(void)layoutSubViews他のいくつかを使用してみましたが、何も機能しません。

私のコードを投稿しましたcellForRowAtIndexPath。これは私のアプリのメモ セクションの一部です。このコードは機能します。編集モードに入ったときにラベルを移動する方法を知る必要があります??

ヒントとアドバイスをありがとう:-)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";

MNCustomCell *cell = [_mainTableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
    cell = [[MNCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}


//cell.textLabel.text = [_tableArray objectAtIndex:indexPath.row];

MNotes *mnotes = [[self fetchedResultsController] objectAtIndexPath:indexPath];

cell.noteTitle.text = mnotes.noteTitleString;
cell.noteSummary.text = mnotes.mainNoteString;

mnotes.createDate = [[NSDate alloc] init];
SORelativeDateTransformer *relativeDateTransformer = [[SORelativeDateTransformer alloc] init];
NSString *relativeDate = [relativeDateTransformer transformedValue:mnotes.createDate];

cell.noteDate.text = relativeDate;


cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;
}

-

//This is the Custom Cell
@interface MNCustomCell : UITableViewCell
{

}

@property (strong, nonatomic) IBOutlet UILabel *noteTitle;
@property (strong, nonatomic) IBOutlet UILabel *noteDate;

@property (strong, nonatomic) IBOutlet UITextView *noteSummary;


@end

-

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Initialization code

    [self.contentView addSubview:_noteTitle];
    [self.contentView addSubview:_noteSummary];
    [self.contentView addSubview:_noteDate];

  }
   return self;
  }
4

3 に答える 3

9

他の解決策はおそらく機能しますが、この方法ではアニメーションが自動的に行われます。 MNCustomCellセルの現在の状態に応じてビューを再レイアウトすることはありませんが、セルの contentView にラベルを追加すると、再レイアウトされます。

次の例では、削除ボタンに干渉しないようにラベルを移動します。

MNCustomCell.m

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 220.0, 15.0)]];
        mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:mainLabel];
于 2012-12-02T07:11:08.193 に答える
1

カスタム セル クラスに次のメソッドを実装します。

- (void)willTransitionToState:(UITableViewCellStateMask)state 

- (void)didTransitionToState:(UITableViewCellStateMask)state

それに応じてラベルを移動します。

次のようになるはずです

- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
       label.frame = ...
    }
}

編集:

- (void)willTransitionToState:(UITableViewCellStateMask)state {

    [super willTransitionToState:state];

//    label.hidden = YES;
//    label.alpha = 0.0;
}

- (void)didTransitionToState:(UITableViewCellStateMask)state {

    [super didTransitionToState:state];

    if (state == UITableViewCellStateShowingDeleteConfirmationMask) {

        [UIView beginAnimations:@"anim" context:nil];
        label.frame = leftFrame;
        [UIView commitAnimations];
    } else if (state == UITableViewCellStateDefaultMask) {

        [UIView beginAnimations:@"anim" context:nil];
        label.frame = rightFrame;
        [UIView commitAnimations];
    }
}
于 2012-12-02T04:04:06.440 に答える