小编Jay*_*lor的帖子

帮助iOS上的setTitle

我是编程的新手.我输入了以下代码,应用程序运行时没有错误,但按下按钮时崩溃.目标是确定按钮是否被按下一次或两次.如果第三次按下它,它应该重置为永不被按下.

buttonTestViewController.h

#import <UIKit/UIKit.h>

@interface buttonTestViewController : UIViewController {
}

-(IBAction)pressButton:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

buttonTestViewController.m

@implementation buttonTestViewController


-(IBAction)pressButton:(id)sender{
static int counter;

if (counter == 0) {
    [sender setTitle:@"not answered"];
}else if (counter == 1) {
    [sender setTitle:@"Pressed Once"];
}else if (counter == 2) {
    [sender setTitle:@"Pressed Twice"];
}
counter += 1;

if (counter > 2) {
    counter = 0;
}
}
- (void)dealloc {
[super dealloc];
}

@end
Run Code Online (Sandbox Code Playgroud)

我还想在按下时更改按钮的背景颜色,如果我使用setBackgroundColor,我会继续出错.提前感谢您的时间和考虑.

cocoa-touch objective-c

0
推荐指数
1
解决办法
1998
查看次数

标签 统计

cocoa-touch ×1

objective-c ×1