#import <UIKit/UIKit.h> @interface demo7_dayViewController : UIViewController { // 用来显示程序结果 IBOutlet UILabel *result; } // 属性声明 @property(nonatomic, retain) UILabel *result; // 同意或反对的值 -(IBAction) agreeDisagree; // 左中右的值 -(IBAction) leftCenterRight; // 从1-100其中之一的值 -(IBAction) oneToHundred; // 左轮枪的值 -(IBAction) ressianRoulette; @end
#import "demo7_dayViewController.h" @interface demo7_dayViewController () @end @implementation demo7_dayViewController // 本指令告诉编译器去合成今天方法所需的结果控件的存储器方法 @synthesize result; /** 同意或反对的值 */ -(IBAction) agreeDisagree{ // 创建一个取得整数的变量,rund%2为变量返回"0"或"1",随机二选一整数 int rNumber = rand() % 2; switch (rNumber) { case 0: result.text = @"同意"; break; case 1: result.text = @"反对"; break; default: break; } } /** 左中右的值 */ -(IBAction) leftCenterRight{ int rNumber = rand() % 3; switch (rNumber) { case 0: result.text = @"左"; break; case 1: result.text = @"中"; break; case 2: result.text = @"右"; break; default: break; } } /** 从1-100其中之一的值 */ -(IBAction) oneToHundred{ int rNumber = rand() % 100; result.text = [NSString stringWithFormat:@"%d", rNumber]; } /** 左轮枪的值 */ -(IBAction) ressianRoulette{ int rNumber = rand() % 6; switch (rNumber) { case 0: result.text = @"砰!!!"; break; default: result.text = @"没事了。。。"; break; } } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } /** 释放可用内存给应用程序,并及时警告提示 */ - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /** 执行内存进行清理工作 */ -(void)dealloc { [result release]; [super dealloc]; } @end