2011-10-27 17 views
0

IBでカスタムセルを作成し、ウィンドウ全体をカバーしないtableViewに表示します。 toolbarを設定し、isEditing属性とボタンのタイトルを切り替えるボタンを付けました。 didSelectRowAtIndexPathif(!self.editing)も作成しました。カスタムセルでモードを編集

ボタンがヒットしたときに編集モードに入っていますが、カスタムセルには左側に削除記号が表示されないというフィードバックがあります。セルをスワイプすると、の右のの削除ボタンが表示されますが、そのボタンを押すとアプリケーションがクラッシュしますが、後でそのアドレスに対処します。

cellforRowAtIndexPathcell.contentviewにカスタムセルを割り当てないと、左の削除記号が表示されないことがあります。私は試して、そしてエラーを得た。

私が愚かな間違いをした場合、私はIBで作られたカスタムセルで初めてです。

私はカスタムセル割り当てるcellForRowAtIndexPath内のコード、:任意の助け

static NSString *CellIdentifier = @"CustomCell";  
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) {   
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];   
    for (id currentObject in topLevelObjects){ 
     if ([currentObject isKindOfClass:[UITableViewCell class]]){ 
      cell = (CustomCell *) currentObject; 
      break; 
     } 
    }   
} 
// some more setup and stuff 
return cell; 

感謝を!

+0

Okkkaaaaayは、申し訳ありませんが、それは、本当に愚かだった.. 私のViewControllerをのUIViewControllerのサブクラスであるため、のUITableViewController、私は必要だろうではありません編集ボタンを自分のトグルにする.MyTableView.editing。 – Nareille

答えて

0

を私のViewControllerをのUIViewController、ないのUITableViewControllerのサブクラスであるため、私が必要としているでしょうこのような編集ボタンをトグルします

- (IBAction)editButtonPressed:(id)sender { 
    if (self.myTableView.isEditing) { 
    self.editButton.title = @"Edit"; 
    self.myTableView.editing = NO; 
    } 
    else{ 
     self.editButton.title = @"Done"; 
     self.myTableView.editing = YES; 
    } 
} 

代わりの

- (IBAction)editButtonPressed:(id)sender { 
    if (self.myTableView.isEditing) { 
     self.editButton.title = @"Edit"; 
     self.myTableView.editing = NO;  
    } 
    else{ 
     self.editButton.title = @"Done"; 
     self.myTableView.editing= YES; 
    } 
} 

それが起こることができますが、あまりにも他の誰かを役に立てば幸い..

0

カスタムセルを作成するには、UITableViewCellのサブクラスを作成します。ビューでペン先を作成し、それにコンセントを接続します

@interface CustomCell : UITableViewCell 
{ 
    IBOutlet UIView* _cellView; 
} 

オーバーライドinitWithStyle:reuseIdentifier:メソッドとそこにペン先をロードします。セルのコンテンツビューにカスタムビューを追加します。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) 
    { 
     [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
     [_cellView setFrame:[[self contentView] bounds]]; 
     [[self contentView] addSubview:_cellView]; 
    } 
    return self; 
} 

その後、あなたは、単に呼び出すcellForRowAtIndexPathコードで:

if (cell == nil) 
{ 
    cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier ] autorelease]; 
} 
+0

o私は正確にはわからないが、この方法の利点は何か、それはちょうど私のセットアップ全体を壊した.-そのセットアップの目的は何か? – Nareille

関連する問題