0

我刚开始 iOS 开发,试图在我的代码中调用一个方法(函数?)。在我的 .h 文件中,我有:

- (void)changeColour;

在我的 .m 文件中,我有:

- (IBAction)leftSwipeDetected:(UISwipeGestureRecognizer *)sender {

    [self changeColour];

}

- (void)changeColour
{
    colourCount++;

    switch (colourCount)
    {
        case 1:

            self.view.backgroundColor = [UIColor redColor];
            break;

        case 2:

            self.view.backgroundColor = [UIColor blueColor];
            break;
    }
}

这会在我运行程序时提示放弃 SIGABRT,而当我没有尝试调用方法时却没有。这有什么问题吗?

谢谢。

4

1 回答 1

0

好吧无论如何试试这个,


  @interface ViewController ()
  {
     int count;
  }

  @end

  @implementation ViewController

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

      UISwipeGestureRecognizer *rec = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeDetected:)];
      rec.direction = UISwipeGestureRecognizerDirectionLeft;
      [self.aView addGestureRecognizer:rec];
      [rec release];
      count = 0;

   }

   - (void)didReceiveMemoryWarning
   {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
   }

    - (void)dealloc {
            [_aView release];
            [super dealloc];
        }


    -(void)leftSwipeDetected:(UISwipeGestureRecognizer *)sender
    {
            [self changeColor];
    }

    -(void)changeColor
    {
            count++;
            switch (count) {
                case 1:
                    {
                        self.aView.backgroundColor = [UIColor blackColor];
                        break;
                    }
                case 2:
                {
                    self.aView.backgroundColor = [UIColor greenColor];
                    break;
                }
                default:
                break;
            }
        if(count == 2)
        {
            count = 0;
        }
    }
  @end


于 2013-07-24T05:17:41.637 回答