我的应用程序的登陆页面是一个 UITableView,其中包含菜单选项列表(menu.h、menu.m)。在 menu,m 的 ViewDidAppear 中,应用程序检查用户是否已登录并转到 Modal Login Form (Login.h, Login.m)。在模式登录表单中,单击登录时会执行委托方法,但未传递值。如果我遗漏了什么,将不胜感激
a) 类 LoggedInUserDetails
a1) 类 LoggedInUserDetails.h
#import <UIKit/UIKit.h>
@interface LoggedInUserDetails : NSObject
@property (nonatomic, copy) NSString *isSuccessfullyLoggedIn;
@property (nonatomic, copy) NSString *login;
@end
a2) LoggedInUserDetails.m
#import "LoggedInUserDetails.h"
@implementation LoggedInUserDetails
@synthesize isSuccessfullyLoggedIn;
@synthesize login;
@end
b) 登录.h 和登录.m
b1) 登录.h
#import <UIKit/UIKit.h>
@class Login;
@class LoggedInUserDetails;
@protocol LoginDelegate <NSObject>
- (void) login:(Login *)controller GetLoggedInUserDetails:(LoggedInUserDetails *)loggedinuserdetails;
@end
@interface Login : UIViewController
@property (nonatomic, weak) id <LoginDelegate> delegate;
- (IBAction)actnLogin:(id)sender;
- (IBAction)actnLogout:(id)sender;
@end
b2) 登录.m
#import "Login.h"
#import "menu.h"
@interface Login ()
@end
@implementation Login
@synthesize delegate;
- (IBAction)actnLogin:(id)sender {
//[self.delegate didReceiveMessage:@"YES"];
LoggedInUserDetails *loggedinuserdetails = [[LoggedInUserDetails alloc] init];
loggedinuserdetails.login = @"MCONNLEY";
loggedinuserdetails.isSuccessfullyLoggedIn = @"YES";
// The line below is getting executed while checking in debug mode but
// doesnot go to menu.m with the result the login form is constantly shown
[self.delegate login:self GetLoggedInUserDetails:loggedinuserdetails];
}
c) 菜单.h 和菜单.m
c1)菜单.h
#import <UIKit/UIKit.h>
#import "Login.h"
#import "LoggedInUserDetails.h"
@interface menu : UITableViewController <LoginDelegate>
@property (strong, nonatomic) NSArray *menuList;
@property (nonatomic, strong) LoggedInUserDetails *userDetails;
@end
c2)菜单.m
#import "menu.h"
@interface menu ()
@end
@implementation menu
@synthesize menuList;
@synthesize userDetails;
- (void) viewDidAppear:(BOOL)animated {
if (![userDetails.isSuccessfullyLoggedIn isEqualToString:@"YES"]) {
[self performSegueWithIdentifier:@"LoginSegue" sender:self];
}
}
- (void) login:(Login *)controller GetLoggedInUserDetails:(LoggedInUserDetails *)loggedinuserdetails {
userDetails = loggedinuserdetails;
IstheUserLoggedIn.text = userDetails.isSuccessfullyLoggedIn;
[self dismissModalViewControllerAnimated:YES];
}