“未完成实施”的警告

时间:2012-05-02 15:27:35

标签: objective-c

我收到了关于“未完成实施”的警告,但与源文件进行比较后无法找出原因。已经注释掉了警告。

我的ItemsViewController.m版本

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

    @implementation ItemsViewController //Incomplete implementation

    - (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];//No known class method for selector 'defaultStore'
      // Incompatible pointer types initializing 'BNRItem*__strong' with an expression of 'NSArray'

      // Figure out where that item is in the array 
      int lastRow = [[[BNRItemStore defaultStore] allItems] indexOfObject:newItem]; //No known class method for selector 'defaultStore'

      NSIndexPath *ip = [NSIndexPath indexPathForRow:lastRow inSection:0];

      // Insert this new row into the table.
      [[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:ip]
                              withRowAnimation:UITableViewRowAnimationTop];
    } 

    - (id)initWithStyle:(UITableViewStyle)style
    {
      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] //No known class method for selector 'defaultStore'
                                           toIndex:[toIndexPath row]];
    }

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

      NSArray *items = [[BNRItemStore defaultStore] allItems];//No known class method for selector 'defaultStore'
      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];//No known class method for selector '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];//No known class method for selector 'defaultStore'
    }
    - (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]//No known class method for selector 'defaultStore'
                    objectAtIndex:[indexPath row]];
      [[cell textLabel] setText:[p description]];
      return cell;
    }

    @end

Original source version of ItemsViewController.m

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

@implementation ItemsViewController
- (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];

    // Figure out where that item is in the array 
    int lastRow = [[[BNRItemStore defaultStore] allItems] indexOfObject:newItem];

    NSIndexPath *ip = [NSIndexPath indexPathForRow:lastRow inSection:0];

    // Insert this new row into the table.
    [[self tableView] insertRowsAtIndexPaths:[NSArray arrayWithObject:ip]
                            withRowAnimation:UITableViewRowAnimationTop];
}  
- (id)initWithStyle:(UITableViewStyle)style
{
    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] init];

    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];
}

- (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

ItemsViewController.h

#import <Foundation/Foundation.h>
#import "DetailViewController.h"

@interface ItemsViewController : UITableViewController
{
  IBOutlet UIView *headerView;
}

-(UIView *)headerView;
-(IBAction)addNewItem:(id)sender;
-(IBAction)toggleEditingMode:(id)sender;

@end

2 个答案:

答案 0 :(得分:1)

您没有在.m文件中实现两个方法(如果我没有严重读取它):

-(UIView *)headerView;
-(IBAction)toggleEditingMode:(id)sender;

这就是你收到警告的原因。

在任何情况下,在您的构建结果窗口中,在您看到带有包含数字的黄色图标的警告的位置,您可以单击黄色图标,将显示更多信息,详细说明您在实现文件中缺少哪些方法

答案 1 :(得分:0)

您似乎没有实施以下两种方法:

-(UIView *)headerView;
-(IBAction)toggleEditingMode:(id)sender;