我想知道在第一堂课或第二堂课时点击按钮,它会计算+1并在第三堂课中发送价值。
在第三课我在scrollview中有按钮作为循环(i = 1; i< 30; i ++) 然后,如果count = 1,则位置i = 1将显示标题“first”,如果count = 2,则位置i = 2将显示标题“second”
在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"];
}
在third.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];
}