ios - 猜猜游戏 Xcode 线程断点

标签 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 应用程序并且模拟器进入后台。之后它以绿色突出显示此行: 如果([field.text intValue] == randomNum)

它说线程 1 断点 1.1

这是什么错误?

最佳答案

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

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

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

关于ios - 猜猜游戏 Xcode 线程断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25900038/

相关文章:

iphone - 主要 nib 文件的窗口或 View

ios - 如何使用 Stackview 消费整个 View

c++ - 使用 for 循环的 OpenGL 立方体

ios - SceneKit - 围绕 X 和 Z 轴旋转对象

ios - 将卡片添加到 Apple Wallet

ios - Rails API 的 POST 方法

xcode - 如何使用 Xcode 3.2 在文件级别前进/后退?

ios - 仅以纵向启动应用程序

ios - 使用核心数据计算多节表的总和

ios - 更新 Firebase 中的数据会删除旧子项并使用 SWIFT 替换它