-2

当我遇到错误时,我正在制作一个名为 iTahDoodle 的程序,我的错误是“'addTask:' 的方法定义未找到”

这是我的代码:

#import "AppDelegate.h"

// Helper function to fetch the path to our ro-do data stored on disk
NSString *docPath()
{
    NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"data.td"];
}

@implementation AppDelegate

#pragma mark - Application delegate callbacks

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //attempt to load an existing to-do dataset from an array stored to disk
    NSArray *plist = [NSArray arrayWithContentsOfFile:docPath()];
    if (plist) {
        //if there was a dataset available, copy it into our instance variable
        tasks = [plist mutableCopy];
    } else {
        //otherwise, just create an empty one to get us started.
        tasks = [[NSMutableArray alloc] init];

    }

    //create and configure the uiwondow instance
    //a cgrect is a struct with an origin (x,y) and size (width,height)
    CGRect windowFrame = [[UIScreen mainScreen] bounds];
    UIWindow *theWindow = [[UIWindow alloc] initWithFrame:windowFrame];
    [self setWindow:theWindow];

    //define the frame rectangles of three UI elements
    //CGrectMake () creates a CGRect from (x,y, width, height}
    CGRect tableFrame = CGRectMake(0, 80, 320, 380);
    CGRect fieldFrame = CGRectMake(20, 40, 200, 31);
    CGRect buttonFrame = CGRectMake(228, 40, 72, 31);

    // create and configure the table view
    taskTable = [[UITableView alloc] initWithFrame:tableFrame
                                             style:UITableViewStylePlain];
    [taskTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    //create and configure the text field where new tasks will be typed
    taskField = [[UITextField alloc] initWithFrame:fieldFrame];
    [taskField setBorderStyle:UITextBorderStyleRoundedRect];
    [taskField setPlaceholder:@"Type a task, Tap Insert"];

    // create and configure a rounded rect insert button
    insertButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [insertButton setFrame:buttonFrame];

    //buttons behave using a target/action callback
    // configure the insert button's action to call this object's -addTask: method
    [insertButton addTarget:self
                     action:@selector(addTask:)
           forControlEvents:UIControlEventTouchUpInside];

    //give the button a title
    [insertButton setTitle:@"Insert"
                  forState:UIControlStateNormal];

    // add our three ui elements to the window
    [[self window] addSubview:taskTable];
    [[self window] addSubview:taskField];
    [[self window] addSubview:insertButton];

    // finalize the window and put it on the screen
    [[self window] setBackgroundColor:[UIColor whiteColor]];
    [[self window] makeKeyAndVisible];

    return YES;

}

我相信这就是您需要查看的所有代码,但如果不是添加评论。

4

1 回答 1

0

您需要在 .m 文件中实现该方法。

于 2013-07-18T00:00:51.123 回答