Iphone UIButton发送者标题问题
这似乎是个很容易的问题,但我不明白。 它有两个UI按钮,一个标题为“下一个”,另一个标题为“上一个”。两者都链接到相同的方法。我只想根据按下的按钮更改变量“helpStatus”:Iphone UIButton发送者标题问题,iphone,objective-c,xcode,Iphone,Objective C,Xcode,这似乎是个很容易的问题,但我不明白。 它有两个UI按钮,一个标题为“下一个”,另一个标题为“上一个”。两者都链接到相同的方法。我只想根据按下的按钮更改变量“helpStatus”: if([sender currentTitle] == @"next"){ helpStatus++; } if ([sender currentTitle] == @"previous"){ helpStatus--; } NSLog(@"
if([sender currentTitle] == @"next"){
helpStatus++;
}
if ([sender currentTitle] == @"previous"){
helpStatus--;
}
NSLog(@"%@", [sender currentTitle]);
记录的滴度是“下一个”和“上一个”,就像它应该的那样,但它不起作用,我不知道为什么。您需要使用,否则您只是比较它们是否是相同的对象,而不是它们是否相等:)
我不会用绳子。如果您决定更改标签,会发生什么情况?考虑使用标签代替.< /P> e、 g.b
button.tag = 100;
...
- (void)buttonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
if(button.tag == 100) {
}
}
或者在你的情况下(我在开玩笑),甚至:
澄清一下,这意味着它们在内存中是相同的对象,而不是相同的字符串。:)
button.tag = 100;
...
- (void)buttonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
if(button.tag == 100) {
}
}
button1.tag = 1;
button2.tag = -1;
...
- (void)buttonPressed:(id)sender {
UIButton *button = (UIButton*)sender;
helpStatus+= button.tag;