Resolved UINavigation bar issue.

Discussion in 'iOS Programming' started by Rudsther2435, May 10, 2013.

  1. Rudsther2435, May 10, 2013
    Last edited: May 10, 2013

    Rudsther2435 macrumors newbie

    Joined:
    May 9, 2013
    #1
    I am stuck.
    I am given three erros, I have put them in bold, please help!

    Code:
    #import "ItemsViewController.h"
    #import "BNRItemStore.h"
    #import "BNRItem.h"
    
    @implementation ItemsViewController [B]HERE [B]I AM GIVEN INCOMPLETE IMPLEMENTATION ON THIS LINE.[/B]
    [/B]
    - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    DetailViewController *detailViewController = [[DetailViewController alloc] init];
    NSArray *items = [[BNRItemStore sharedStore] allItems];
    BNRItem *selectedItem = [items objectAtIndex:[indexPath row]];
    
    [detailViewController setItem:selectedItem];
    
    [[self navigationController] pushViewController:detailViewController animated:YES];
    }
    
    - (id)init
    {
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
    UINavigationItem *n = [self navigationItem];
    [n setTitle:@"Carventory"];
    
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc]
    initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
    action:@selector(addNewItem:)];
    [[self navigationItem] setRightBarButtonItem:bbi];
    
    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]];
    }
    return self;
    }
    
    - (id)initWithStyle:(UITableViewStyle)style
    {
    return [self init];
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    return [[[BNRItemStore sharedStore] allItems] count];
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    UITableViewCell *cell =
    [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    
    if (!cell) {
    cell = [[UITableViewCell alloc]
    initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
    }
    
    BNRItem *p = [[[BNRItemStore sharedStore] allItems] objectAtIndex:[indexPath row]];
    
    [[cell textLabel] setText:[p description]];
    
    return cell;
    
    
    [B]- (IBAction)addNewItem:(id)sender[/B] [I]expected expression[/I]
    {
    BNRItem *newItem = [[BNRItemStore sharedStore] createItem];
    
    int lastRow = [[[BNRItemStore sharedStore] allItems] indexOfObject:newItem];
    
    NSIndexPath *ip = [NSIndexPath indexPathForRow:lastRow inSection:0];
    
    [[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:ip]
    withRowAnimation:UITableViewRowAnimationTop];
    }
    
    - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
    BNRItemStore *ps = [BNRItemStore sharedStore];
    NSArray *items = [ps allItems];
    BNRItem *p = [items objectAtIndex:[indexPath row]];
    [ps removeItem:p];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
    }
    
    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
    {
    [[BNRItemStore sharedStore] moveItemAtIndex:[sourceIndexPath row] toIndex:[destinationIndexPath row]];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
    [super viewWillAppear:animated];
    [[self tableView] reloadData];
    }
    @end
    [B]at very end here i get the message [I]'missing @end'[/I][/B]
    
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    You haven't closed your tableView:cellForRowAtIndexPath: method properly.
     
  3. Rudsther2435 thread starter macrumors newbie

    Joined:
    May 9, 2013
  4. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #4
    Dont forget to indent your code

    Saves you from these kind of problems plus makes your code look cleaner and easier to understand
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Agreed. An easy way to re-indent your code in Xcode is to select the text, and then simply Control-I (or, via the menus, Editor > Structure > Re-indent).
     

Share This Page