我是 obj-c 的新手,我正在尝试编写一个简单的 IBAction,其中一旦单击按钮就会更改其标签。它适用于图像背景和静态字符串,但是当它崩溃时:
int i = (arc4random()%90);
NSString *lab = [NSString stringWithFormat:@"%d", i];
[sender setText:lab];
为什么?提前ty
编辑:这是整个方法
-(IBAction) toggleUIButtonImage:(id)sender{
NSString *img = @"bulldog-cute-tom-bancroft.jpg";
NSString *imgSel = @"kitten-cute-tom-bancroft.jpg";
UIImage *unselectedImage = [UIImage imageNamed:img];
UIImage *selectedImage = [UIImage imageNamed:imgSel];
if ([sender isSelected]) {
[sender setBackgroundImage:unselectedImage forState:UIControlStateNormal];
[sender setSelected:NO];
}else {
[sender setBackgroundImage:selectedImage forState:UIControlStateSelected];
[sender setSelected:YES];
}
int i = (arc4random()%90);
NSString *lab = [NSString stringWithFormat:@"%d", i];
[sender setTitle:lab forState: UIControlStateNormal];
}