2012-03-06 11 views
5

のセルを返しません。私は、再利用可能なUITableViewCellのサブクラス(具体的にはTDBadgedCell)を使用したいので、ビューのストーリーボードデザイナーでセルのビジュアル要素を設計したくありません。dequeueReusableCellWithIdentifier私はUITableViewCellのサブクラスでのUITableViewControllerとiOS5をストーリーボードを使用しています私のカスタムタイプ

ストーリーボードデザイナーでセル識別子を設定していて、TDBadgedCell固有のプロパティを設定していない限り、すべての行がUITableViewで正しく読み込まれます。 badgeStringプロパティをTDBadgedCellに固有のものに設定した場合、例外が発生します。 dequeueReusableCellWithIdentifier:がTDBadgedCell型のセルを返さないことを絞りました。

私はUITableViewControllerでこれを実行しています。私は埋め込まれたUITableViewと同様の方法で設定されたUIViewControllerを持っており、それは問題ではありません。何か案は?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath 
{ 
static NSString *CellIdentifier = @"PhoneNumberCell"; 
TDBadgedCell *cell = (TDBadgedCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell == nil) { 
    cell = [[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

if ([cell isKindOfClass:[TDBadgedCell class]]) 
{ 
    NSLog(@"It is TDBadgedCell"); 
} 
else 
    NSLog(@"It is NOT TDBadgedCell"); 
+6

また、「カスタムクラス」をストーリーボードデザイナーのTDBadgedCellに変更しましたか? – fengd

+0

[ストーリーボードの代わりにペン先のプロトタイプセル]の可能な複製(http://stackoverflow.com/questions/8574188/prototype-cells-in-a-nib-instead-of-a-storyboard) - 可能な限り、私はあなたがこのセルのための別のxibを持っているかどうか分からない。 – jrturton

+0

June1st - それはそれでした!ありがとう!私は答えとしてあなたの答えを記入する方法をよく分かりません。 – scubasteve

答えて

0

私はUITableViewCellのサブクラス化が、ストーリーボードを使用していないという点で、同様の問題がありました。ここでは、ユーザーがアプリのロック解除機能を購入したかどうかによって、さまざまなセルクラスを使用するという私の解決策があります。誰かを助けることを願っています。一言で言えば

は、私はUITextViewオブジェクトを含む複数のオブジェクトを持つセルを持っていました。私はLite版でUITextViewオブジェクトのコピーアンドペースト機能をロックダウンしたいが、ユーザがアプリ内製品で購入した後はその機能をリリースしたいと思っていた。

そのまま私は2つのUITableViewCellクラス、UITextViewのものを持っていたし、UITextViewを持つ別のcanBecomeFirstresponderはNOを返すとサブクラス化。そのようにしても、ユーザーはUITextviewデータを上下にスクロールできますが、データをコピー&ペーストすることはできません。ここで

はコードであり、私がしなければならなかったすべては、再利用識別子の名前を変更しました。

なぜですか?セルがまだ存在していたので、[self.tableview reloadData]は新しいクラスでセルを再構築しないためです。画面の新しいセルは新しいクラスを取得しますが、既存のセルは新しいクラスを取得しません。このソリューションは、購入後に一度オフにして追加した機能をすべて解除します。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


if (your test if in-app was purchased is yes) 
{ 
static NSString *MyIdentifier = @"MyCell"; 

FrontCell *cell = (FrontCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 

if (cell == nil) 
     { 
     cell = [[FrontCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.shouldIndentWhileEditing = NO; 
    } 

//....///  

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row]; 
cell.trackDetails.delegate = self; 
cell.trackDetails.tag = indexPath.row; 


return cell; 
} 
else // inapp not purchased 
{ 
    static NSString *MyLockedIdentifier = @"MyLockedCell"; 

    FrontCellLocked *cell = (FrontCellLocked *)[tableView dequeueReusableCellWithIdentifier:MyLockedIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[FrontCellLocked alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyLockedIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.shouldIndentWhileEditing = NO; 
    } 

    //....///  

cell.trackDetails.text = [yourObject objectAtIndex:indexPath.row]; 
cell.trackDetails.delegate = self; 
cell.trackDetails.tag = indexPath.row; 


return cell; } 
} 
0

ストーリーボードでは、UITablviewCellのサブクラスのカスタムクラスプロパティを設定できます。
dequeueReusableCellWithIdentifierメソッドは、サブクラスの型のセルを返します。

0

私はセルをデキューする方法が間違っていると思います。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *cell = [self.tblProfileInfo dequeueReusableCellWithIdentifier:@"PostCell" forIndexPath:indexPath]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 

} 

最後にindexPathを忘れました。

+0

"TDBadgedCell * cell =(TDBadgedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];" 〜 "TDBadgedCell * cell =(TDBadgedCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];" –

関連する問題