@Protocol& Delegate - 调用Delegate方法,但不将值传递给父表单

时间:2012-11-18 18:34:44

标签: xcode ios5

我的应用程序的登陆页面是一个UITableView,它有菜单选项列表(menu.h,menu.m)。在菜单的ViewDidAppear中,m,应用程序检查用户是否已登录并执行模式登录表单(Login.h,Login.m)。在模态登录表单中,单击“登录”,将执行委托方法,但不传递值。如果我遗漏了某些东西,我将不胜感激

a)Class LoggedInUserDetails

a1)Class 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)Login.h&amp; Login.m

b1)Login.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)Login.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)Menu.h&amp; Menu.m

C1)Menu.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)Menu.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];
}

1 个答案:

答案 0 :(得分:0)

您似乎没有在任何地方设置委托。我期待在prepareForSegue中看到这一点。

即将展示的视图控制器将在segue.destinationViewController中提供。您可以在此处将self设置为委托。