I am a begginer with Objective-C programming. I searched here and in other websites to a way to solve my problem but i did not find. I want to create an login view before the system load. Then, after login i want to dismiss it. On my project i use ARC and not use Storyboards.
When i debug and look into the function "efetuarLogin" the value of property delegate is 0x000000. I think it is blank, is not? According to the tutorials and other tips i found on the internet, this is the right way to code delegate. Can you check this for me? Here is the code:
Login.h
#import <UIKit/UIKit.h>
@class Login;
@protocol LoginDelegate <NSObject>
@required
    - (void)loginDidFinish: (Login *)login;
@end
@interface Login : UIViewController{
    __weak id<LoginDelegate> delegate;
}
@property (nonatomic, weak) id <LoginDelegate> delegate;
- (IBAction)efetuarLogin:(id)sender;
@end
Login.M
#import "Login.h"
@implementation Login
@synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)efetuarLogin:(id)sender {
    [delegate loginDidFinish:self];
}
@end
MainController.h
#import <UIKit/UIKit.h>
#import "Login.h"
@interface MainController : UITabBarController <LoginDelegate>
@end
MainController.m
#import "MainController.h"
#import "Login.h"
#import "ModalViews.h"
#import "Alerts.h"
#import "ViewPadrao.h"
#import "TableView.h"
@implementation MainController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    ModalViews *modalViews = [[ModalViews alloc] initWithNibName:@"ModalViews" bundle:nil];
    Alerts *alerts = [[Alerts alloc] initWithNibName:@"Alerts" bundle:nil];
    ViewPadrao *viewPadrao = [[ViewPadrao alloc] initWithNibName:@"ViewPadrao" bundle:nil];
    TableView *tableView = [[TableView alloc] initWithNibName:@"TableView" bundle:nil];
    self.viewControllers = @[modalViews, alerts, viewPadrao, tableView];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    Login *login = [[Login alloc] initWithNibName:@"Login" bundle:nil];
    [login setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentViewController:login animated:NO completion:nil];
}
- (void)loginDidFinish: (Login *)login{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sua mensagem aqui" message:@"Mensagem" delegate:self cancelButtonTitle:@"Fechar" otherButtonTitles:nil];
    [alert show];
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
And the method didFinishLaunchingOptions of AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    mainController = [[MainController alloc] init];
    window.rootViewController = mainController;
    [window makeKeyAndVisible];
    return YES;
}
Sorry for the high quantity of code. I am thankful since already!!
I am using the ViewDidAppear method to show Login to users. But when i dismiss and the MainController appears, the method viewdidapper creates the Login again. How i do to show login once? When i tried to do this on viewdidload it did not work. The login did not appear.
 
    