2012-01-11 9 views
0

私は、コアデータを使って物事を管理しています。次に、物事のリストを表示するためにUITableViewController/UITableViewCellを使用しています。しかし、Thingオブジェクトには、UITableViewCellのテキストプロパティで表示するものよりも多くのデータがあります。また、UITableViewControllerからより詳細なView Controllerに分割すると、本当に必要なのはThingオブジェクトへのポインタなのでそれを次のView Controllerに渡すことができます。例えばiOS用のuserData UITableViewCell

:今

-(UITableViewCell*)tableView:(UITAbleView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
ENTRY_LOG; 
// Ask the NSFetchedResultsController for the NSManagedUserObject at the row in question 
Thing* thing = [self.fetchedResultsController objectAtIndexPath:indexPath]; 

// For brevity skip dequeueReusable... 

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
cell.textLabel.text = thing.name; 

EXIT_LOG; 
return cell; 

は、私がセグエが適切に接続されていると仮定仮定:

- (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender { 
    ENTRY_LOG; 

    UITableViewCell* cellSender = (UITableViewCell*)sender; 

    // I want to do this: 
    Thing* thingHandle = [cellSender someMessageToGetThingReference]; 
    [segue.destinationViewController setThing:thing]; 

    // and I don't want to do this 
    // setup NSFetchRequest and predicate to get thing where 'name = cellSender.text' 
    [segue.destinationViewController setThing:thing];  

    EXIT_LOG; 
} 

私はその後、私のNSFetchResultsControllerのにを使用することができますでセルがあることをindexPathを得ることができた場合少なくとも、objectAtIndexPathをもう一度取得します。おそらく、 - (NSIndexPath *)indexPathForSelectedRowをprepareForSegueの中でUITableViewに対して呼び出してそこから処理します。

答えて

1

はおそらく、私は何かを明らかに行方不明ですが、セルのインデックスのパスを取得するには、使用、あなたがのUITableViewControllerからsegueingされていることができないと仮定すると:

NSIndexPath * indexPath = [[自己のtableView] indexPathForCell:cellSender] ;

+0

ありがとうございます!あなたのソリューションは、私のすべての問題をUITableViewCellで解決します! –

関連する問題