2013-03-24 56 views
-4

我是xcode的新手。我尝试了一个小时,但我不能。我如何修复? 我正在尝试做一个待办事项列表。相同的代码适用于其他视图控制器。我没有复制粘贴代码。我做了更正,然后出现这个错误。预先感谢您的帮助。不完整的实现警告和构建错误

TodoMaster2ViewController.h

#import <UIKit/UIKit.h> 
#import "TodoTask2.h" 

@interface TodoMaster2ViewController : UITableViewController 

- (IBAction)done2:(UIStoryboardSegue *)sender; 
- (IBAction)cancel2:(UIStoryboardSegue *)sender; 
- (IBAction)buttonEditClick2:(UIBarButtonItem *)sender; 
- (void) tableView2: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath; 

@end 

TodoMaster2ViewController.m

#import "TodoMaster2ViewController.h" 
#import "TodoDetailViewController.h" 
#import "TodoAdd2ViewController.h" 

@interface TodoMaster2ViewController() { 
    NSMutableArray *_objects2; 
} 
@end 

@implementation TodoMaster2ViewController 
- (void)awakeFromNib 
{ 
    [super awakeFromNib]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    /* 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)]; 
    self.navigationItem.rightBarButtonItem = addButton; 
    */ 
    UIApplication *app = [UIApplication sharedApplication]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:app]; 


    NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    // paths[0]; 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; 
    if ([fileManager fileExistsAtPath:plistPath] == YES) 
    { 
     NSMutableArray *readArray = [NSMutableArray arrayWithContentsOfFile:plistPath]; 
     _objects2 = [[NSMutableArray alloc] init]; 
     NSEnumerator *enumerator = [readArray objectEnumerator]; 
     NSString *str = [[NSString alloc] init]; 
     while (str = [enumerator nextObject]) 
     { 
      todoTask2 *tempTodo = [[todoTask2 alloc] init]; 
      tempTodo.taskName2 = str; 
      str = [enumerator nextObject]; 
      tempTodo.checked2 = str; 
      [_objects2 addObject:tempTodo]; 

     } 
     [[self tableView] reloadData]; 
    } 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
/* 
- (void)insertNewObject:(id)sender 
{ 
if (!_objects) { 
_objects = [[NSMutableArray alloc] init]; 
} 
[_objects insertObject:[NSDate date] atIndex:0]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 
*/ 
#pragma mark - Table View 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return _objects2.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

    NSDate *object = _objects2[indexPath.row]; 
    cell.textLabel.text = [object description]; 
    return cell; 
} 

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [_objects2 removeObjectAtIndex:indexPath.row]; 
     [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 
    } 
} 

/* 
// Override to support rearranging the table view. 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
} 
*/ 

/* 
// Override to support conditional rearranging of the table view. 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
// Return NO if you do not want the item to be re-orderable. 
return YES; 
} 
*/ 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"showDetail"]) { 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     NSDate *object = _objects2[indexPath.row]; 
     [[segue destinationViewController] setDetailItem:object]; 
    } 
} 
#pragma mark yeni-task 
- (IBAction)done:(UIStoryboardSegue *)segue; 
{ 
    if ([[segue identifier] isEqualToString:@"DoneAdd"] || 
     [[segue identifier] isEqualToString:@"DoneKeyboard"]) { 
     TodoAdd2ViewController *addController = [segue sourceViewController]; 
     if (![addController.textFieldTask2.text isEqualToString:@""]) { 
      if (!_objects2) { 
       _objects2 = [[NSMutableArray alloc] init]; 
      } 
      todoTask2 *test = [[todoTask2 alloc] init]; 
      test.taskName2 = addController.textFieldTask2.text; 
      if (addController.durum2.isOn) { 
       test.checked2 = @"yes"; 
      } else { 
       test.checked2 = @"no"; 
      } 
      [KGStatusBar showSuccessWithStatus:@"Yeni Fikir Eklendi!"]; 
      //[_objects insertObject:[[NSMutableAttributedString alloc] initWithString:addController.textFieldTask.text] atIndex:_objects.count]; 
      [_objects2 insertObject:test atIndex:_objects2.count]; 
      [[self tableView] reloadData]; 
      addController.textFieldTask2.text = @""; 
     } 
     [self dismissViewControllerAnimated:YES completion:NULL]; 
     [self setEditing: NO animated: YES]; 
    } 
} 
#pragma mark task tamamlandı 
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    todoTask2 *temp = [_objects2 objectAtIndex:[indexPath row]]; 
    if([temp.checked2 isEqualToString:@"yes"]) 
    { 

     NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:temp.taskName2]; 
     [tempString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, [tempString length])]; 
     [tempString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, [tempString length])]; 
     cell.imageView.image = [UIImage imageNamed:@"check.png"]; 
     [[cell textLabel] setAttributedText:tempString]; 
    } 
    else 
    { 
     NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:temp.taskName2]; 
     cell.imageView.image = [UIImage imageNamed:@"uncheck.png"]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
     [[cell textLabel] setAttributedText:tempString]; 
    } 
} 
- (IBAction)cancel:(UIStoryboardSegue *)segue; 
{ 
    if([[segue identifier] isEqualToString:@"CancelAdd"]) { 
     TodoAdd2ViewController *addController = [segue sourceViewController]; 
     addController.textFieldTask2.text = @""; 
     [self dismissViewControllerAnimated:YES completion:NULL]; 
    } 
} 

- (IBAction)buttonEditClick:(UIBarButtonItem *)sender { 
    if (self.tableView.editing) 
     [[self tableView] setEditing:NO animated:YES]; 
    else 
     [[self tableView] setEditing:YES animated:YES]; 
} 
- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath 
{ 
    todoTask2 *temp = [_objects2 objectAtIndex:[indexPath row]]; 
    if([temp.checked2 isEqual: @"yes"]) 
    { 
     temp.checked2 = @"no"; 
     /* 
     [[_objects objectAtIndex:[indexPath row]] addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])]; 
     [[_objects objectAtIndex:[indexPath row]] addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleNone] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])]; 
     [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone; 
     */ 
    } 
    else 
    { 
     temp.checked2 = @"yes"; 
     /* 
     [[_objects objectAtIndex:[indexPath row]] addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])]; 
     [[_objects objectAtIndex:[indexPath row]] addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])]; 

     [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; 
     */ 
    } 
    [[self tableView] reloadData]; 
    //[_objects setObject: atIndexedSubscript:[indexPath row]] 
} 

- (void)applicationDidEnterBackground:(NSNotification *)notification { 
    NSLog(@"Entering Background"); 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    // paths[0]; 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:@"data.plist"]; 
    //NSArray *keys = [[NSArray alloc] initWithObjects:@"task", nil]; 
    NSMutableArray *array = [[NSMutableArray alloc] init]; 
    NSEnumerator *enumerator = [_objects2 objectEnumerator]; 
    todoTask2 *tempTodo; 
    while (tempTodo = [enumerator nextObject]) 
    { 
     [array addObject:tempTodo.taskName2]; 
     [array addObject:tempTodo.checked2]; 
    } 
    [array writeToFile:plistPath atomically:YES]; 
} 
@end 

对不起这一点。这是我的错误。 http://d.pr/i/s40r

+0

我不会读取所有代码并猜测错误。如果您在帖子中包含警告/错误。 – 2013-03-24 19:19:18

+0

你收到的错误信息是什么? – matt 2013-03-24 19:19:21

+0

你的错误在哪里? – 2013-03-24 19:21:28

回答

0

完全执行通常意味着你已经声明在.h文件中的一些方法,但在你的.m文件还没有编写所有的实现。如果您认为您已经编写了这些实现,请检查两个文件中的方法签名是否完全相同。您也可以声明tableView2:didSelectRowAtIndexPath:。可能你想在这里只声明委托方法tableView:didSelectRowAtIndexPath:(no 2)并检查哪个表视图在该方法内发送消息。这可能是导致错误的方法,因为我看不到代码中的实现(我快速检查过,所以它可能实际上在那里)。