Display UIAlertView in NSObject class

I am creating a login system for my application that will be called several times. Therefore, instead of copying and pasting the code at several points, I, of course, create the NSObject class, so instead I can call the class.

The login system displays UIAlertView, and when you click "OK", the system will try to enter the system. I can call the class and UIAlertView will be displayed, but I can’t tell which buttons are involved. Here is my code:

//Calling the login system

Login *login = [[Login alloc] init];

Login.h

#import <Foundation/Foundation.h>

@interface Login : NSObject <UIAlertViewDelegate> {

}

@end

Login.m

#import "Login.h"

@implementation Login

+(void)initialize {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Login" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];

    [alert show];
    [alert release];

    NSLog(@"Testing");

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex  {

    NSLog(@"Here");

    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];  

    if([title isEqualToString:@"OK"]) {

        NSLog(@"Tapped");

    }

}

@end

For now, before I put UITextFields in the view, I just want the application to know which button was clicked. Testingappears in the log but is not displayed Hereand Tapped. Thank!

+5
source share
4

+ (void) initialize, init - (id) init, .

"+ (void) initialize" .

"- (id) init" , init, ( ) .

-(id)init {

    //alert view

    self = [super init];

    return self;

}
+1

switch(buttonIndex){
    case 0:
        NSLog(@"Tapped First Button");
        break;
    case 1:
        break;
    default:
        break;
}
0

self , , . - . , , Login , .

0

:

Create a property of the NSObject class in the controller class of the form:

in h file:

@property (non-atomic, save) LoginCheckNSObject * LoginCheckerObject;

in file m:

self.LoginCheckerObject=[[LoginCheckNSObject alloc] init];
[self.LoginCheckerObject setDelegate:self];
[self.LoginCheckerObject TrackNowLogin];
0
source

All Articles