How can I find out the current name of a viewcontroller in iphone
I have a BaseView that implements a UIViewController. Every view in the project must implement this BaseView.
In BaseView, I have a method:
-(void) checkLoginStatus
{
defaults = [[NSUserDefaults alloc] init];
if(![[defaults objectForKey:@"USERID"] length] > 0 )
{
Login *login=[[Login alloc] initWithNibName:@"Login" bundle:nil];
[self.navigationController pushViewController:login animated:TRUE];
[login release];
}
[defaults release];
}
The problem is that my login view also implements BaseView, validates the login and reopens the LoginView, i.e. it gets stuck in a recursive call.
Can I check the checkLoginStatus method if the request belongs to the LoginView and then take no action to check the registration. Example:
- (void) checkLoginStatus
{
**if(SubView is NOT Login){**
defaults = [[NSUserDefaults alloc] init];
if(![[defaults objectForKey:@"USERID"] length] > 0 )
{
Login *login=[[Login alloc] initWithNibName:@"Login" bundle:nil];
[self.navigationController pushViewController:login animated:TRUE];
[login release];
}
[defaults release];
}
}
Please, help..
a source to share
Use the following method:
if ([self isMemberOfClass:[Login class]])
{
CFShow(@"Yep, it the login controller");
}
isMemberOfClass
indicates whether the instance is an exact instance of this class. There's also isKindOfClass
:
if ([self isKindOfClass:[BaseView class]])
{
CFShow(@"This will log for all classes that extend BaseView");
}
isKind verifies that the class is an extension of some class.
So, given your example:
-(void) checkLoginStatus
{
defaults = [[NSUserDefaults alloc] init];
if (![self isMemberOfClass:[Login class]])
{
if (![[defaults objectForKey:@"USERID"] length] > 0 )
{
Login *login=[[Login alloc] initWithNibName:@"Login" bundle:nil];
[self.navigationController pushViewController:login animated:TRUE];
[login release];
}
}
[defaults release];
}
a source to share
Add one parameter to checkLoginStatus and set this parameter when you call the method from LoginView and in checkLoginStatus check this parameter, if this parameter is set skip this block ... ie
if(![[defaults objectForKey:@"USERID"] length] > 0 && var1 != TRUE)
{
Login *login=[[Login alloc] initWithNibName:@"Login" bundle:nil];
[self.navigationController pushViewController:login animated:TRUE];
[login release];
}
a source to share