IBAction控制太多动作

时间:2014-06-13 04:19:57

标签: ios xcode ibaction

我正在尝试创建一个tapper应用程序并且我已经设置了我的操作,但它控制了太多的操作。当我点击一个敲击器时,该值将在一个标签中上升而在另一个标签中不会,但是当我点击另一个敲击器时,该值将在另一个标签中上升。例如,如果一个标签有3个而我点击另一个标签并且它为0则它将变为4。

小时。文件

{
BOOL newmedia;

IBOutlet UILabel *Label;
IBOutlet UILabel *LabelOne;
IBOutlet UIImage *myImageView;

int Number;


}

- (IBAction)Submit:(id)sender;
- (IBAction)openMail:(id)sender;
- (IBAction)Subtract:(id)sender;
- (IBAction)Addition:(id)sender;

@property (strong, nonatomic) IBOutlet UIScrollView *grillretterScroller;
@property (strong, nonatomic) IBOutlet UIScrollView *rememberContentOffset;
@property (strong, nonatomic) IBOutlet UITextField *textfield;
@property (strong, nonatomic) IBOutlet UITextField *AddNotesTextField;
@property(nonatomic,assign) id<MFMailComposeViewControllerDelegate> mailComposeDelegate;
@property BOOL newmedia;
@property BOOL mailComposeController;
@end

m.file

 - (IBAction) Addition: (UIButton*) sender
 {
     const int firstButtonTag = 101;
     const int otherButtonTag = 102;

     if (sender.tag == firstButtonTag) {

         Number += 1;
         Label.text = [NSString stringWithFormat:@"%d",Number];
}
     else if (sender.tag == otherButtonTag) {

         Number += 1;
         LabelOne.text = [NSString stringWithFormat:@"%d",Number];
     }
 }

Starts Equal

About to click button for label above 3 to go up

Button is clicked and image value increases one more than the other

1 个答案:

答案 0 :(得分:0)

这是因为您对两个标签使用相同的Number值。您需要存储每个标签的当前值。