GuessingGame Xcode线程断点

时间:2014-09-17 20:44:33

标签: ios xcode

//
//  GGViewController.m
//  GuessingGame
//
//  Created by NEIU Developer on 9/3/14.
//  Copyright (c) 2014 NEIU Developer. All rights reserved.
//

#import "GGViewController.h"


@interface GGViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputText;
-(IBAction)guess:(id)sender;

@end
@implementation GGViewController
-(IBAction)guessNumber:(id)sender
{

    if([field.text intValue] == randomNum)
    {
        label.text=[NSString stringWithFormat: @"Correct!"];

    }
    else if([field.text intValue] > randomNum)
    {
        label.text=[NSString stringWithFormat: @"Incorrect, Guess Lower!"];
    }
    else if([field.text intValue] < randomNum)
    {
        label.text=[NSString stringWithFormat: @"Incorrect, Guess Higher!"];
    }
}



- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    randomNum = arc4random() % 11;
    label.text = [NSString stringWithFormat:@"Between 1-10"];
    self.inputText.delegate=self;

}

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

-(BOOL) textFieldShouldReturn: (UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}


- (IBAction)guess:(id)sender {

}
@end


// nssstring to integer

//getting random number to objective c

//int r =arc4random() 

____________________________

//
//  GGViewController.h
//  GuessingGame
//
//  Created by NEIU Developer on 9/3/14.
//  Copyright (c) 2014 NEIU Developer. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface GGViewController : UIViewController<UITextFieldDelegate>
{

    int randomNum;
    IBOutlet UITextField *field;
    IBOutlet UILabel *label;
}

-(IBAction)guessNumber:(id)sender;

@end

_____________________

我创建了一个基本的xcode猜谜游戏。游戏允许您猜测1-10之间的数字,并告诉您它是低或高。当我运行游戏时,它会回到xcode应用程序并且模拟器进入后台。之后,它以绿色突出显示此行:   if([field.text intValue] == randomNum)

它表示线程1断点1.1

这是什么错误?

1 个答案:

答案 0 :(得分:2)

您的按钮正在运行此方法,猜测。
     - (IBAction)猜测 :( id)发件人{     //空方法     }

但是您已经将该方法的所有代码放在一个不同的方法中,guessNumber      - (IBAction) guessNumber :( id)发件人{     //你的代码在这里     }

因此,当您单击该按钮时,它会运行空方法猜测,并且您的guessNumber方法未被调用。