Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I customize the UITableView that users see depending on which cell in the previous view they chose?
    primarykey
    data
    text
    <p>I have a navigation-based iOS application. In my <code>RootViewController</code>, users see chapters from 1 to 18. When they select a cell, it takes them to the <code>VersesViewController</code>, where they see another list from Verse 1 to whatever. Depending on what chapter they chose, they will see a different number of verses.</p> <p>I would like to modify the contents of an <code>NSArray</code> in the <code>VersesViewController</code> when the user chooses a cell in the <code>RootViewController</code> view. How can I do this?</p> <p>Here is the <code>RootViewController</code> code:</p> <pre><code>#import "RootViewController.h" @implementation RootViewController - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Chapters"; chapterList = [[NSMutableArray alloc] init]; for (int i = 1; i&lt;19; i++) { [chapterList addObject:[NSString stringWithFormat:@"Chapter %d", i]]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [chapterList count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } cell.textLabel.text = [chapterList objectAtIndex:indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { VersesViewController *detailViewController = [[VersesViewController alloc] initWithNibName:@"VersesViewController" bundle:nil]; if ([[chapterList objectAtIndex:indexPath.row] isEqual:@"Chapter 9"]) { [detailViewController setNumberOfVerses:18]; } else { [detailViewController setNumberOfVerses:72]; } [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)viewDidUnload { [super viewDidUnload]; self.title = nil; } - (void)dealloc { [super dealloc]; [chapterList release]; } @end </code></pre> <p>Please note that I am a n00b at Obj-C so I will need very simple answers. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload