-4

私はxcodeの初心者です。1時間試していますが、できませんでした。どうすれば修正できますか?やることリストを作ろうとしています。同じコードが他のビューコントローラでも機能します。コードをコピーしてlongに貼り付けました。修正したところ、このエラーが発生しました。よろしくお願いします。

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:(no 2)を宣言し、そのメソッド内でどのテーブルビューがメッセージを送信しているかを確認することです。コードに実装が表示されないため、エラーの原因となっているのはそのメソッドである可能性があります(すばやく確認したので、実際に存在する可能性があります)。

于 2013-03-24T19:29:51.567 に答える