2012-05-02 71 views
-2

我收到了'未完成實施'的警告,但無法找到原因,並將其與源文件進行了比較。已將警告註釋掉。'未完成實施'的警告

我的版本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

警告詳細告訴你缺什麼。 –

+1

我們需要看到頭文件。不完整的實現是由於您沒有實現您在頭文件中聲明的方法或者您符合的必需協議方法。 – Joe

+0

我從來沒有看到這個細節。它發生在我在標題中定義一個方法並忘記實現它的時候。 –

回答

1

您還沒有實現在.m文件兩種方法(如果我不讀書是很糟糕):

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

這就是爲什麼你會收到警告。

在任何情況下,在你的構建結果窗口中,右鍵,你看到包含數字的黃色圖標警告時,您可以點擊黃色圖標和更多的信息將出現正是細節你在你的執行缺少哪些方法文件。

+0

固定它;非常感謝你! – pdenlinger

0

您不會出現已實現了以下兩種方法:

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