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:
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!
source
share