私は、コアデータを使って物事を管理しています。次に、物事のリストを表示するために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に対して呼び出してそこから処理します。
ありがとうございます!あなたのソリューションは、私のすべての問題をUITableViewCellで解決します! –