You already have the iVar sum
in place - you just need to total it with every button press. As @Wain suggested, you should change to NSInteger rather than int, but either way will work.
Also, since you are using the value of the button, you only need a single action handler for all of your buttons - in IB, just connect the touchUpInside
to a single IBAction buttonPressed:(id)sender
-(IBAction) buttonPressed:(id)sender
{
UIButton *button=(UIButton *)sender;
sum += [button.titleLabel.text intValue];
myLabel.text = [NSString stringWithFormat:@"value: %d",sum];
}
Also, while there is nothing wrong with using an iVar, it is preferable to use properties -
@interface ViewController : UIViewController
@property (weak,nonatomic) IBOutlet UILabel *mylabel;
@property NSInteger sum;
@end
-(IBAction) buttonPressed:(id)sender
{
UIButton *button=(UIButton *)sender;
self.sum += [button.titleLabel.text intValue];
self.myLabel.text = [NSString stringWithFormat:@"value: %d",self.sum];
}