Hello future friends who is gonna help me big time on this project,
I have these Books parsed from XML file (adopted from this post I found). First view (RootViewController) has a list of book titles in a UITable. When user clicks on one of the books, instead of viewing the books detail (BooksDetailViewController) in a second UITable, I would like the Title, Author and Summary to be in a custom view laid out in Interface Builder with UILabels and UITextView.
IBOutlet UILabel *bookTitle;
IBOutlet UILabel *bookAuthor;
IBOutlet UITextView *bookSummary;
I believe my problem has to do with RootViewController.m “didSelectRowAtIndexPath”. If I understand the example I had adapted properly (which I am not confident about), it passed the Book array into each row of the new table on my BooksDetailViewController.
Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
I have tried a few things to recreate didSelectRowAtIndexPath, but I am not having much luck. Below I have the example code commented out and with my own terrible guessed code /sigh.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// if(bdvController == nil)
// bdvController = [[BookDetailViewController alloc] initWithNibName:@"BookDetailView" bundle:[NSBundle mainBundle]];
// Book *aBook = [appDelegate.books objectAtIndex:indexPath.row];
// bdvController.aBook = aBook;
// [self.navigationController pushViewController:bdvController animated:YES];
NewBookDetailViewController *detailViewController = [[NewBookDetailViewController alloc] initWithNibName:@"NewBookDetailViewController" bundle:nil];
Book *aBook = appDelegate.books;
//detailViewController.aBook.title = bookTitle.text;
//detailViewController.aBook.author = bookAuthor.text;
//detailViewController.aBook.summary = bookSummary.text;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
Do I actually connect the parsed data aBook.title to bookTitle (UILabel) in didSelectRowAtIndexPath of RootViewController?
or
Do I connect them in viewDidLoad in NewBookDetailViewController.m?
bookTitle.text = aBook.title;
bookAuthor.text = aBook.author;
bookSummary.text = aBook.summary;
What is the proper way to write the didSelectRowAtIndexPath in RootViewController for a custom view instead of a table view?
Please take it easy on me.
- Clo
The purpose of
NewBookDetailViewControlleris to display information about a single book, yes? SoNewBookDetailViewControllerwill need a way of being told which book it’s supposed to display.An easy way of doing this would be to add a property to this class to hold a reference to the
Bookit’s supposed to display. You would not want to pass the entire array of books to the detail view controller. How is it supposed to know which single book to display?Here’ how my implementation would look:
Here’s how you add the
bookproperty toNewDetailViewController:The
.hfile:The
.mfile: