我有 5 个标签栏项目。第一个将是登录页面。当用户未登录时,其他选项卡 bat 项目将被禁用,但当用户通过单击 navigationItem 按钮登录时,所有其他 4 个选项卡 bat 项目将被启用。
我已经进行了搜索,但一无所获...... :(
这是我的代码:
MainTabViewController.h
#import <UIKit/UIKit.h>
@interface MainTabViewController : UITabBarController
@property (retain, nonatomic) IBOutlet UITabBar *MainTabBar;
@end
MainTabViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UITabBarItem *tabBarItem = [[MainTabBar items] objectAtIndex:1];
[tabBarItem setEnabled:FALSE];
}
LoginViewController.h
#import <UIKit/UIKit.h>
@interface LoginViewController : UIViewController
@property (retain, nonatomic) IBOutlet UITextField *CustomerUsername;
@property (retain, nonatomic) IBOutlet UITextField *CustomerPassword;
- (IBAction)ResignKeyboardClicked:(id)sender;
@end
LoginViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIBarButtonItem *btnGo = [[UIBarButtonItem alloc] initWithTitle:@"Login" style:UIBarButtonItemStyleBordered target:self action:@selector(loginAction)];
self.navigationItem.rightBarButtonItem = btnGo;
}
- (void) LoginAction {
AppDelegate *passData = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if ([CustomerUsername.text isEqualToString:@""] || [CustomerPassword.text isEqualToString:@""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Please Fill all the field" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
// i will use a code from connect to DB tutorial
NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/Staff.php?userName=%@&password=%@",CustomerUsername.text, CustomerPassword.text];
// to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
// to receive the returend value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
if ([strResult isEqualToString:@"1"])
{
//MainTabViewController *main = [[MainTabViewController alloc] initWithNibName:nil bundle:nil];
//UITabBarItem *tabBarItem = [[main.MainTabBar items] objectAtIndex:1];
//[tabBarItem setEnabled:TRUE];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"You are now Logged In" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
else
{
// invalid information
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"Invalide Information" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
}
现在我的代码只禁用了其他 4 个选项卡栏项目,但我不知道在用户登录时启用所有选项卡 bat 项目的方法。
请帮忙?
谢谢!:D