-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

4

1 回答 1

0

不完整的实现通常意味着您已经在文件中声明了一些方法.h,但还没有在.m文件中编写所有实现。如果您认为您已经编写了这些实现,请检查两个文件中的方法签名是否完全相同。

另外,您声明tableView2:didSelectRowAtIndexPath:. 可能您在这里想要的只是声明委托方法tableView:didSelectRowAtIndexPath:(第 2 种)并检查哪个表视图在该方法中发送消息。可能是导致错误的方法,因为我在您的代码中看不到实现(我很快检查了,所以它实际上可能在那里)。

于 2013-03-24T19:29:51.567 回答