0

即使我没有更改相关方法中的任何内容,我也会在 ItemsViewController.m 中遇到重复的问题。之前我在 SO 上问过一些问题,然后更正了它们,但它们又出现了。没有对再次引起大惊小怪的方法/领域进行任何更改。已注释掉问题区域。

会不会有编译器问题?

这是文件;提前致谢。

项目视图控制器.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 '}'
4

1 回答 1

1

此行似乎缺少块的结尾:

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

应该:

[detailViewController setDismissBlock:^{[[self tableView]reloadData]}];
于 2012-05-02T19:37:44.403 回答