我想知道当点击头等舱或二等舱的按钮时,它将计数+1并在三等舱发送值。
在第三类中,我在滚动视图中有按钮作为循环( i = 1; i < 30; i++)然后如果位置 i = 1 处的 count = 1 按钮将显示标题“第一”,如果位置 i = 2 处的 count = 2 按钮将显示标题“第二”
在 first.h 和 second.h
IBOutlet UIButton*countBtn;
NSInteger tapCount;
在 first.m 和 second.m
-(IBAction)CountButton:(id)sender{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
tapCount += 1;
[defaults setObject:[NSNumber numberWithInt:tapCount] forKey:@"buttonPress"];
}
在第三.m
NSInteger i;
int x = 60;
for ( i = 1; i < 30; i++){
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(x, 20, 120, 120);
button.tag = i;
x = x+170;
[scrollView addSubview:button];
}
[scrollView setScrollEnabled:YES];
scrollView.ContentSize = CGSizeMake(5000, 130);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *loadCount = [defaults objectForKey:@"buttonPress"];
int Count = [loadCount intValue];
if (Count = 1){
button.tag = 1;
[button setTitle:@"first" forState:UIControlStateNormal];
}
else if (Count = 2){
button.tag = 2;
[button setTitle:@"second" forState:UIControlStateNormal];
}