gpt4 book ai didi

ios - 当导航到另一个页面时需要添加事件指示器

转载 作者:行者123 更新时间:2023-11-29 01:01:22 32 4
gpt4 key购买 nike

#import "LoginVC.h"
#import "HOMEVC.h"
#import "DashboardVC.h"
@interface LoginVC ()

@end

@implementation LoginVC
UIActivityIndicatorView *spinner ;
-(IBAction)login:(id)sender{

NSString *userUpdate =[NSString stringWithFormat:@"%@",[Usernamefileld text]];
NSString *userUpdate1 =[NSString stringWithFormat:@"%@",[PasswordField text]];
NSString *baseURL = [NSString stringWithFormat:@"http://192.168.1.200:8094/YazakiService.svc/LOGIN/%@/%@",userUpdate,userUpdate1];
NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSMutableArray *serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSLog(@"got response==%@", serviceResponse);
NSDictionary *template=[serviceResponse objectAtIndex:0];

NSString *test=[template objectForKey:@"ValidState"];
// NSString *test1=[template objectForKey:@"Userid"];
NSString *helloString = @"1";
// //
// NSString *helloString1 =@"LFY430";
if ([test isEqual:helloString]) {
[NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil];
[self moveToView];

// UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Login Successfully" message:@"Correct Uername/Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

}
else{

UIAlertView *alert2=[[UIAlertView alloc]initWithTitle:@"Login Failed" message:@"Incorrect Uername/Password" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];

[alert2 show];
[self alertView1:alert2 didDismissWithButtonIndex:alert2];

}

}

- (void)viewDidLoad {

[super viewDidLoad];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 225, 20, 30)];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
spinner.color = [UIColor blackColor];
[self.view addSubview:spinner];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

-(void)moveToView{

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];


DashboardVC *initView = (DashboardVC*)[storyboard instantiateViewControllerWithIdentifier:@"Dashboardvc"];

[initView setModalPresentationStyle:UIModalPresentationFullScreen];

[spinner stopAnimating];
[self presentViewController:initView animated:NO completion:nil];
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self moveToView];
}

- (void) alertView1:(UIAlertView *)alertView1 didDismissWithButtonIndex:(NSInteger)buttonIndex
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginVC *initView = (LoginVC*)[storyboard instantiateViewControllerWithIdentifier:@"loginvc"];
[initView setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:initView animated:NO completion:nil];
}
-(void)threadStartAnimating:(id)data
{
[spinner startAnimating];
}


@end

在这里,我初始化了指示器并启动和停止旋转器,但它对我来说不起作用......任何人都可以帮助我解决如何在导航另一个 View 时添加事件指示器的问题

提前致谢

最佳答案

[self.view addSubview:spinner];

在这一行,您将事件指示器添加到当前的 ViewController View 。

但是一旦你导航到其他 View

DashboardVC *initView =  (DashboardVC*)[storyboard instantiateViewControllerWithIdentifier:@"Dashboardvc"];
[self presentViewController:initView animated:NO completion:nil];

当前 View 更改为新 ViewController 的 View 。该 View 中不存在事件指示器,因此您不会在那里看到您的事件指示器。

要解决,你应该在第二个 ViewController 的 viewDidLoad 方法中再次添加事件指示器在仪表板 VC 中

- (void)viewDidLoad {

[super viewDidLoad];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(150, 225, 20, 30)];
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
spinner.color = [UIColor blackColor];
[self.view addSubview:spinner];
}

A better solution would be to use third party progress huds which make the loading indicator part absolutely easy like MBProgressHUD

关于ios - 当导航到另一个页面时需要添加事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36951854/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com