내 응용 프로그램에서 처음 사용자 인 경우 특별한 viewController를 열려고합니다. 이전에 다른 상황에서이 작업을 수행했지만 어떤 이유로 작동하지 않습니다. 두 가지 접근 방식을 시도했지만 어느 것도 작동하지 않습니다. 내가 시도한 첫 번째 일은 appDelegate에서 바로 확인하고 수행하는 것입니다. 그런 다음 루트 뷰 컨트롤러 viewDidLoad 메서드에서 처음 이었는지 확인하고 처음으로 seque를 호출하여 특수 등록 페이지를 여는 경우 . Niether가 작동하고 있는데 왜 그런지 모르겠다 ..... 내가 사용하고있는 코드 중 일부는 다음과 같다.프로그래밍 방식으로 segue가 작동하지 않음
이것은 rootviewcontroller 내부에있다. 내가 그것을 할 때 로그에 "Main is First Time"이 인쇄되어서 거기에있는 것을 알게됩니다. 내가 AppDelegate에 내부
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if([appDelegate firstTime])
{
[self performSegueWithIdentifier:@"mToRegister" sender:self];
NSLog(@"Main is First time");
}
// Do any additional setup after loading the view.
}
.... 스토리 보드에서 SEGUE를 확인을 두 번과 이름이 정확한지에 오른쪽 장소에서 진행됩니다
NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults]
BOOL haveused = [standardUserDefaults boolForKey : @ "haveused"];
if(haveused){
//NOT THEIR FIRST TIME
//Handle scenario
firstTime = NO;
NSString* guid = [[NSMutableString alloc]initWithString:[self getMacAddress]];
//interest = [appDelegate interest];
NSString *splitter = [[NSString alloc]initWithString:@"&"];
NSMutableString *post = [[NSMutableString alloc]initWithString: @"user_read=1&guid="];
[post appendString:guid];
NSLog(@"String for Post is %@", post);
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setValue:@"Basic ==" forHTTPHeaderField:@"Authorization"];
[request setURL:[NSURL URLWithString:@"http://something.com/app/usercrud.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
theConnection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
}
else {
NSLog(@"This is the First time");
firstTime = YES;
//THEIR FIRST TIME
//Handle scenario
// UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
// bundle: nil];
//
// UIViewController *controller = (UIViewController*)[mainStoryboard
// instantiateViewControllerWithIdentifier: @"register"];
// UIViewController *root = (UIViewController *)self.window.rootViewController;
// [root presentModalViewController:controller animated:YES];
[self.window.rootViewController performSegueWithIdentifier:@"mToRegister" sender:self];
}
왜 작동하지 않는가? 아무도이 상황을 처리하는 더 좋은 방법을 안다면?
확인해 보니 nsdefaults가 정상적으로 작동합니다 ... IF 부분을 게시 할 예정입니다. – Rmyers
허위? 당신의 문제는 해결 되었습니까? – Saad
아니요 ... 사용자 기본값이 정상적으로 작동하고 있습니다. 그것은 그것이 처음인지 아닌지 완벽하게 식별합니다. 처음에는 루트보기 컨트롤러가 아닌 다른 페이지를로드하는 것처럼 보일 수 없습니다 ... 내 문제는 무엇입니까 – Rmyers