我想通过改变测试来制作一个可以在两个不同阶段之间翻转的按钮。所以如果它说添加,你点击我更改删除。如果它说删除它将改为添加。
该计划无效, 尝试调试它,我把setTitle方法放在oncreate上,它在那里工作。接下来,我在我的方法中设置断点。它检测到它说添加,并执行了假设改变文本的行,文本没有改变。我真的不明白为什么它适用于oncreate方法而不是我的方法。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
mFeetImage.contentMode = UIViewContentModeScaleAspectFit;
[gFileName Reset];
NSString *ted= [gFileName GetFileName];
mFeetImage.image= [ UIImage imageNamed :ted];
// test code
[ mFavrest setTitle: @"ADD" forState:UIControlStateNormal ]; works
}
-(IBAction) aFavest: (id) sender
{
NSString *t=mFavrest.currentTitle;
int i=[ t compare:@"ADD" ];
if ( i ==0 )
{
// set break point here, break point goes off text does not change
[ mFavrest setTitle: @"REMOVE" forState:UIControlStateNormal ];
}
else
{
[ mFavrest setTitle: @"ADD" forState:UIControlStateNormal];
}
}
答案 0 :(得分:0)
请尝试以下代码:
-(IBAction) aFavest: (id) sender
{
UIButton *youButton = (UIButton*)sender;
if ([youButton.currentTitle isEqualToString:@"ADD"])
{
// set break point here, break point goes off text does not chnage
[youButton setTitle: @"REMOVE" forState:UIControlStateNormal ];
}
else
{
[youButton setTitle: @"ADD" forState:UIControlStateNormal];
}
}
另外,请确保变量mFavrest
已正确连接。在某处放置一个断点并检查它是否为零。
如果IBOutlet mFavrest正确连接且IBAction也是如此,则此代码应该有效。