我试图做一个测试应用程序,当用户点击一个按钮,文本将被切换到别的东西,如果它再次点击,它会回来,但我也希望能够加入其中,用户所以说进入他/她的名节,隐藏的信息是:或任何...的iOS采取用户输入,并将它保存为一个全局变量
我的代码是:
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//button.backgroundColor = [UIColor redColor];
button.titleLabel.textColor=[UIColor blackColor];
button.frame = CGRectMake(25, 100, 275, 60);
[button setTitle:@"Press this button to reveal the text!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(button_method:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)button_method:(UIButton *)button {
NSString *test = @"I am learning Objective-C for the very first time! Also, this is my first ever variable!";
// handle button press
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 60)];
label.text = test;
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
//label.lineBreakMode = NSLineBreakByWordWrapping; //iOS 6 only
[self.view addSubview:label];
[button setTitle:@"You have pressed the button!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(change_again:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)change_again:(UIButton *)button {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 60)];
label.text = @"You have found the next piece of text!";
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
//label.lineBreakMode = NSLineBreakByWordWrapping; //iOS 6 only
[self.view addSubview:label];
[button setTitle:@"Keep pressing!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(button_method:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
希望这不被认为是太本地化!
muqman
PS:A面的问题,我将如何创建这样一个字符串作为NSString *var4 = var.var2.var3;
什么是连接字符?在JavaScript它+
在PHP它.
写了一个计算器应用程序对于你身边的问题:'的NSString * VAR4 = [NSString的stringWithFormat :@“%@%@%@”,var,var2,var3];'(对于你的主要问题,我不明白你在问什么,你说的是“全局”,但你可能只需要一个属性你的控制器......不知道。) –
@phillipMills好吧,即时消息不太好用XCode条款,这是我的第一天编程... – user115422
如果这些是字符串文字,你可以使用它作为'NSString * var4 = @“一些“@”text“@”here“@”!“;' – iDev