0

我正在尝试组合一个应用程序,该应用程序具有一组文本,当用户按下按钮翻页时,这些文本可以随机化。基本上,按下按钮会做两件事;翻页并将文本更改为随机包含的短语。

我试图通过将页面卷曲到同一个 XIB 文件中来实现这一点,并且只更改文本。页面卷曲有效,但不会更改文本。不知道我在这里做错了什么

这是我的代码:

@implementation InfoViewController

@synthesize isViewPushed;


 // Implement viewDidLoad to do additional setup after loading the view.
- (void)viewDidLoad {


if(isViewPushed == NO) {

 { UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 btn.frame = CGRectMake(200, 300, 100, 50);
 [btn setTitle:@"Next" forState:UIControlStateNormal];
 [btn addTarget:self action:@selector(cancel_Clicked:)     forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:btn];
}

{ UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 btn.frame = CGRectMake(20, 300, 100, 50);
[btn setTitle:@"Previous" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(next_clicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}

int  text = rand() % 5;
switch (text) {
 case 0:
 textview.text = @"Hello 1" ;
 break;
case 1:
textview.text = @"Hello 2" ;
break;
case 2:
textview.text = @"Hello 3" ;
break;
case 3:
textview.text = @"Hello 4" ;
break;
case 4:
textview.text = @"Hello 5" ;
break;

}
}
}


-(void) cancel_Clicked:(id)sender {

[self.navigationController dismissModalViewControllerAnimated:YES];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];

[UIView commitAnimations];
}

-(void) next_clicked:(id)sender {


 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:1.0];
 [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view  cache:YES];
 [UIView commitAnimations];
}

任何帮助都会很棒。

4

1 回答 1

0

我看不到您在此处设置文本值的位置:

[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view  cache:YES];

...set or update text value here....

 [UIView commitAnimations];

或之后

[UIView commitAnimations];

...set or update text value here....
于 2010-09-07T14:25:54.463 回答