我正在写一个闪屏。启动画面将连接到服务器并接收一些数据。成功接收数据后,我想以编程方式转到下一个 View Controller 。我怎样才能实现这个目标?这和点击按钮不一样吗?因为即使我将代码放入 LoadingViewContrller 的 viewDidLoad 中,我也不会转发到下一个屏幕。
TableViewController *tvc = [[TableViewController alloc] init];
tvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tvc animated:NO];
我想在检索完所有数据后自动跳转到 TableViewContrller。
下面是我从网络检索数据时的代码。
- (void)fetchedData:(NSData *)responseData {
if(responseData == nil){
[ErrorViewController showError];
}else{
//methods to start parsing and adding json into array
if(delegate){
[delegate jsonReceivedData:array];
//codes to go to next screen should be here
}
}
最佳答案
好的,方法很简单。使应用程序的第一个屏幕与启动屏幕相同。声明并实例化一个 NSTimer,可能在 viewWillAppear 中,如下所示:
mainTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
然后实例化一个BOOL:
- (void)fetchedData:(NSData *)responseData {
if(responseData == nil){
[ErrorViewController showError];
}else{
//methods to start parsing and adding json into array
if(delegate){
[delegate jsonReceivedData:array];
myBool = YES;
}
}
在计时器访问的方法(在本例中为“updateTime”)中执行以下操作:
-(void)updateTime{
if(myBool){
[mainTimer invalidate];
MyViewController *vC = [[MyViewController alloc] init];
//pass vC information, now that it has been initialized
//or pass information to a singleton, from which vC can retrieve it
// (I can show you how to do that, too, if need be)
//I will assume you are using a navigationController
[self.navigationController pushViewController:vC animated:YES];
}
}
由于篇幅原因,我省略了 mainTimer
和 myBool
的声明。
关于xcode - 在 Xcode 中的 viewController 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10104605/