小弟今天刚刚开始接触,照着官网说的整了一个helloworld,结果就是不行。跪求指点~~~~Orz以下是错误代码,我表示完全晕菜了
GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov  3 21:59:02 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".Attaching to process 1967.
2013-05-10 16:22:16.922 HelloWorld[1967:f803] -[ViewController setUserName:]: unrecognized selector sent to instance 0x68419d0
2013-05-10 16:22:16.935 HelloWorld[1967:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ViewController setUserName:]: unrecognized selector sent to instance 0x68419d0'
*** First throw call stack:
(0x13ba052 0x154bd0a 0x13bbced 0x1320f00 0x1320ce2 0x2f1b 0x13bbec9 0x145c2 0x1455a 0xb9b76 0xba03f 0xb92fe 0x39a30 0x39c56 0x20384 0x13aa9 0x12a4fa9 0x138e1c5 0x12f3022 0x12f190a 0x12f0db4 0x12f0ccb 0x12a3879 0x12a393e 0x11a9b 0x2908 0x2865)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language:  auto; currently objective-c
(gdb) 

解决方案 »

  1.   

    意思是说编译器不认识setUserName这个方法
      

  2.   

    -[ViewController setUserName:]: unrecognized selector sent to instance 0x68419d0
      

  3.   

    我在补充一下我的.m和.h文件,其中二楼兄弟说的那个setuserName方法,官方教程上不是说自动生成么。
    这是.h文件
    //
    //  ViewController.h
    //  HelloWorld
    //
    //  Created by Mahmood1 on 5/10/13.
    //  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
    //#import <UIKit/UIKit.h>@interface ViewController : UIViewController <UITextFieldDelegate>
    //- (IBAction)changeGreeting:(id)sender;
    @property (copy,nonatomic)NSString *userName; //官方教程说写了这句,自动生成get和set方法,那又为什么会出这个错呢?@end这是.m文件
    //
    //  ViewController.m
    //  HelloWorld
    //
    //  Created by Mahmood1 on 5/10/13.
    //  Copyright (c) 2013 __MyCompanyName__. All rights reserved.
    //#import "ViewController.h"
    @interface ViewController();
    @property (weak, nonatomic) IBOutlet UILabel *label;
    @property (weak, nonatomic) IBOutlet UITextField *textField;
    - (IBAction)changeGreeting:(id)sender;
    @end
    @implementation ViewController
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Release any cached data, images, etc that aren't in use.
    }#pragma  - View lifecycle- (void)viewDidLoad
    {
        [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    }- (void)viewDidUnload
    {
        [self setTextField:nil];
        [self setLabel:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }- (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    }- (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
    }- (void)viewWillDisappear:(BOOL)animated
    {
    [super viewWillDisappear:animated];
    }- (void)viewDidDisappear:(BOOL)animated
    {
    [super viewDidDisappear:animated];
    }- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        // Return YES for supported orientations
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }- (IBAction)changeGreeting:(id)sender {
        self.userName = self.textField.text;
        NSString *nameString = self.userName;
        if ([nameString length] == 0) {
            nameString = @"World!";
        }
        NSString *greeting = [[NSString alloc]initWithFormat:@"Hello,%@!",nameString];
        self.label.text = greeting;
    }-(BOOL)textFieldShouldReturn:(UITextField *)theTextField{
        if (theTextField == self.textField) {
            [theTextField resignFirstResponder];
        }
        return YES;
    }
    @end
      

  4.   


    #import "ViewController.h"
    @interface ViewController();
    @property (weak, nonatomic) IBOutlet UILabel *label;
    @property (weak, nonatomic) IBOutlet UITextField *textField;
    - (IBAction)changeGreeting:(id)sender;
    @end
    @implementation ViewController
    @synthesize userName;缺少这句@synthesize userName;