List of all Iphone and Blackberry Development codes in a one click Iphone,objective C,xcode,blackberry Development,iOS Development

Friday, July 5, 2019

iOS Decimal in Textfield

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *str =@"0.00";
    if([string isEqual:@""]){
        if(textField.text.length==0){
            textField.text= str;
            return NO;
        }else{
            NSArray *items = [[NSString stringWithFormat:@"%f",[textField.text doubleValue]*0.1] componentsSeparatedByString:@"."];

            NSMutableArray *array = [NSMutableArray array];
            NSString *str = items[1];
            for (int i = 0; i < [str length]; i++) {
                NSString *ch = [str substringWithRange:NSMakeRange(i, 1)];
                [array addObject:ch];
            }

            str=[NSString stringWithFormat:@"%@.%@%@",items[0],array[0],array[1]];
            textField.text= str;
            return NO;
        }
    }else{

        if(textField.text.length==0){
             float f = [[NSString stringWithFormat:@"%@%@",textField.text,string] floatValue];
            str=[NSString stringWithFormat:@"%.2f",f*0.01];
            textField.text= str;
        }else{
            //str=[NSString stringWithFormat:@"%.2f",f*10];
            NSString *fullText=[NSString stringWithFormat:@"%@%@",textField.text,string];

            NSArray *items = [fullText componentsSeparatedByString:@"."];

            NSMutableArray *array = [NSMutableArray array];
            NSString *str = items[1];
            for (int i = 0; i < [str length]; i++) {
                NSString *ch = [str substringWithRange:NSMakeRange(i, 1)];
                [array addObject:ch];
            }

            NSString *firstValue=@"";
            if([items[0] isEqualToString:@"0"]){
                firstValue=array[0];
            }else{
                firstValue=items[0];
                firstValue=[firstValue stringByAppendingString:array[0]];
            }
            NSString *strVal=[NSString stringWithFormat:@"%@.%@%@",firstValue,array[1],array[2]];
            str=strVal;
            textField.text= str;
        }

        return NO;
    }
    textField.text= str;
   // textField.text= [NSString stringWithFormat:@"%f",f*0.01];
    return NO;



}

Wednesday, May 8, 2019

ios Objectice C API Calling Custom Class

Login.h class

#import <UIKit/UIKit.h>
#import "API_Services.h"

@interface ViewController : UIViewController<UITextFieldDelegate,APIServicesListener>
{
UITextField *emailTextField,*passwordTextField;
}
@property (strong, nonatomic) UIWindow *window;



@end


 Login.m Class
 On Login Button Call the Below to hit the API Call

  [[API_Services sharedInstance]login:emailTextField.text password:passwordTextField.text andListener:self];

Callback---

-(void)APIServicesResult:(NSString *) success withResult:(NSDictionary *)result statusCode:(NSString *)statusCode headerFields:(NSDictionary *)headerFields{
[load hideView];
// Util *util = [[Util alloc]init];
NSLog(@"result----------->%@",result);
if([statusCode isEqualToString:@"200"]){
BOOL successFail=[[result objectForKey:@"Status"] boolValue];
if(successFail){
}
else {
NSString *errMsg;
if([result objectForKey:@"message"]){
errMsg=[result objectForKey:@"message"];
}else{
errMsg=[result objectForKey:@"Error"];
}
[self alertViewShow:errMsg];
}
}
else if([statusCode isEqualToString:@"1"]){
[self alertViewShow:STRING_No_Network_ERROR];
}
}




ZIP File

Friday, May 12, 2017

iOS Singleton Class


To set values, use the below code.

YourSingletonClass *sharedManager = [YourtSingletonClass sharedManager];
sharedManager.nameString =@"name";
sharedManager.emailString =@"name@domain.com";

For getting values, use the below code
YourSingletonClass *sharedManager = [YourtSingletonClass sharedManager];
NSString *nameVal=sharedManager.nameString;
NSString *emailVal=sharedManager.emailString;


/////YourSingletonClass.h class

#import

@interface YourSingletonClass : NSObject{
    NSString *nameString;
    NSString *emailString;
}

@property (nonatomic, strong) NSString *nameString;
@property (nonatomic, strong) NSString *emailString;
+ (id)sharedManager;
@end

/////YourSingletonClass.m class

#import "YourSingletonClass.h"
@implementation YourSingletonClass
@synthesize nameString;
@synthesize emailString;

+ (id)sharedManager {
    static YourSingletonClass *sharedMyManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedMyManager = [[self alloc] init];
    });
    return sharedMyManager;
}

- (id)init {
    if (self = [super init]) {
        self.nameString = @"";
        self.emailString = @"";
    }
    return self;
}

- (void)dealloc {
    // Should never be called, but just here for clarity really.
}
@end