2012-05-02 42 views
0

即使我沒有改變相關方法中的任何內容,我也會在ItemsViewController.m中重複出現問題。在此之前,我曾詢問過一些問題,然後糾正了它們,但它們再次出現。沒有對正在大吵大鬧的方法/領域做出任何改變。已經評論了問題領域。ItemsViewController.m中的重複問題

有沒有編譯器問題?

這是文件;提前致謝。

ItemsViewController.m

#import "ItemsViewController.h" 
#import "BNRItemStore.h" 
#import "BNRItem.h" 

@implementation ItemsViewController //@end is missing in implementation context 

- (id)init 
{ 
    // Call the superclass's designated initializer 
    self = [super initWithStyle:UITableViewStyleGrouped]; 
    if (self) { 
    UINavigationItem *n = [self navigationItem]; 

    [n setTitle:@"Homepwner"]; 

    // Create a new bar button item that will send 
    // addNewItem: to ItemsViewController 
    UIBarButtonItem *bbi = [[UIBarButtonItem alloc] 
          initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
          target:self 
          action:@selector(addNewItem:)]; 

    // Set this bar button item as the right item in the navigationItem 
    [[self navigationItem] setRightBarButtonItem:bbi]; 

    [[self navigationItem] setLeftBarButtonItem:[self editButtonItem]]; 
    } 
    return self; 
} 

- (IBAction)addNewItem:(id)sender 
{ 
    // Create a new BNRItem and add it to the store 
    BNRItem *newItem = [[BNRItemStore defaultStore] createItem]; 

    DetailViewController *detailViewController = [[DetailViewController alloc]initForNewItem:YES]; 

    [detailViewController setItem:newItem]; 

    [detailViewController setDismissBlock:^{[[self tableView]reloadData]; 

    UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:detailViewController]; 

    [navController setModalPresentationStyle:UIModalPresentationFormSheet]; 

    [self presentViewController:navController animated:YES completion:nil]; 


    } 

- (id)initWithStyle:(UITableViewStyle)style //use of undeclared identifier 'initWithStyle' 
{ 
    return [self init]; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    [[self tableView] reloadData]; 
} 

- (void)tableView:(UITableView *)tableView 
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath 
     toIndexPath:(NSIndexPath *)toIndexPath 
{ 
    [[BNRItemStore defaultStore] moveItemAtIndex:[fromIndexPath row] 
             toIndex:[toIndexPath row]]; 
} 



- (void)tableView:(UITableView *)aTableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    DetailViewController *detailViewController = [[DetailViewController alloc] initForNewItem:NO]; 

    NSArray *items = [[BNRItemStore defaultStore] allItems]; 
    BNRItem *selectedItem = [items objectAtIndex:[indexPath row]]; 

    // Give detail view controller a pointer to the item object in row 
    [detailViewController setItem:selectedItem]; 

    // Push it onto the top of the navigation controller's stack 
    [[self navigationController] pushViewController:detailViewController 
             animated:YES]; 
} 



-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)io 
{ 
    if ([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad) { 
    return YES; 
    } else { 
    return (io==UIInterfaceOrientationPortrait); 
    } 
} 

- (void)tableView:(UITableView *)tableView 
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // If the table view is asking to commit a delete command... 
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    { 
    BNRItemStore *ps = [BNRItemStore defaultStore]; 
    NSArray *items = [ps allItems]; 
    BNRItem *p = [items objectAtIndex:[indexPath row]]; 
    [ps removeItem:p]; 

    // We also remove that row from the table view with an animation 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
        withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section 
{ 
    return [[[BNRItemStore defaultStore] allItems] count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Create an instance of UITableViewCell, with default appearance 
    // Check for a reusable cell first, use that if it exists 
    UITableViewCell *cell = 
    [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; 

    // If there is no reusable cell of this type, create a new one 
    if (!cell) { 
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault 
      reuseIdentifier:@"UITableViewCell"]; 
    } 
    // Set the text on the cell with the description of the item 
    // that is at the nth index of items, where n = row this cell 
    // will appear in on the tableview 
    BNRItem *p = [[[BNRItemStore defaultStore] allItems] 
       objectAtIndex:[indexPath row]]; 
    [[cell textLabel] setText:[p description]]; 
    return cell; 
} 

@end // expected '}' 

回答

1

這行看起來失蹤到底塊:

[detailViewController setDismissBlock:^{[[self tableView]reloadData]; 

應該是:

[detailViewController setDismissBlock:^{[[self tableView]reloadData]}];