ユニバーサル マスター/ディテール アプリケーションを作成しました。カスタム クラス (MasterViewController クラス) 内にテーブル ビューがあります。これは UITableViewController クラスです。Storyboard を使用して、iPhone のテーブル ビューにカスタム セルを作成しました。カスタム セルには、3 つのラベルと 1 つの画像が含まれています。StoryBoard では、このテーブル ビュー データソースとデリゲートが MasterViewController クラスに設定されます。カスタム テーブル ビュー セルの属性インスペクターの [ビュー] セクションで [ユーザー インタラクションが有効] になっています。私の MasterViewController クラスでは、「numberOfSectionsInTableView」などの UITableViewDataSource メソッドが正常に動作しています。テーブル ビューと詳細ビューの間にシークが定義されています。アプリケーションを実行してテーブル ビューでセルを選択すると、iPhone に対して didSelectRowAtIndexPath が呼び出されません。
didSelectRowAtIndexPath が実行されていないことに関するかなりの数の投稿を読みましたが、問題を解決できませんでした。
どんなヒントでも大歓迎です。
カスタム セル識別子は ConversationCell です。セグエ識別子は ShowConversationDetails です。numberOfRowsInSection の最初の行にブレークポイントを設定してデバッグしましたが、このメソッドは入力されません。
セグエが機能し、詳細ビューに「Hello」テキスト付きのラベルが表示されます。
いくつかのコード:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
//NSLog(@"Rows %lu",(unsigned long)[sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ConversationCell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
[[self.fetchedResultsController sections] count]);
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
self.detailViewController.detailItem = object;
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowConversationDetails"]) {
NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];
Event *e = nil;
e = [self.fetchedResultsController objectAtIndexPath:selectedIndex];
UIViewController *destinationViewController = [segue destinationViewController];
[segue.destinationViewController setLabel:@"Hello"];
}
}
MASTERVIEWCONTROLLER: 上記のインターフェイスは次のとおりです。
@interface MasterViewController : UITableViewController <NSFetchedResultsControllerDelegate,ASIHTTPRequestDelegate,UITableViewDelegate, UITableViewDataSource>
{
NSMutableArray *eventsArray;
}
これは私の問題の手がかりになるかもしれません。次のコードを prepareForSeque に追加すると
NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];
NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:selectedIndex];
NSString *messageTableID = [[object valueForKey:@"messagetableid"] description];
selectedIndex は、prepareForSeque の実行時に行が選択されていないかのように空です。
ちなみに、安全のために、シミュレーターからアプリを削除してから、プロジェクトでクリーンを実行しましたが、何も変わりませんでした。
ティム