Pages

Labels

Friday, June 1, 2012

Edit the Tableview Cell

- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    
    //ADDING And Deleting CEll
    
    
    
    
    if (editingStyle == UITableViewCellEditingStyleDelete) 
{
        [Arr removeObjectAtIndex:indexPath.row];
[tab reloadData];
    } else if (editingStyle == UITableViewCellEditingStyleInsert)
{
        @try {
            [Arr addObject:addname.text];
        }
        @catch (NSException *exception) {
            [Arr addObject:@""];
        }
        [tab reloadData];
    }
}

Tuesday, May 29, 2012

Adding validation to UITextfields

Create the Function Named validate Input &Defined it as Given Below



-(BOOL)validateInput{
    
    BOOL retvalue=YES;
    NSString *throwmessage;
    
    if ([LocationName.text isEqualToString:@""] || LocationName.text==nil ) 
        
    {
        throwmessage=@"Please Enter Location Name";
        retvalue=NO;
    }
    
    else if ([City.text isEqualToString:@""] || City.text==nil ) 
        
    {
        throwmessage=@"Please Enter City ";
        retvalue=NO;
    }
    else if ([Area.text isEqualToString:@""] || Area.text==nil ) 
        
    {
        throwmessage=@"Please Enter Area ";
        retvalue=NO;
    }
    
    else if ([State.text isEqualToString:@""] || State.text==nil ) 
        
    {
        throwmessage=@"Please Enter State";
        retvalue=NO;
    }
    
    else if ([Country.text isEqualToString:@""] || Country.text==nil ) 
        
    {
        throwmessage=@"Please Enter Contact Number ";
        retvalue=NO;
    }
      
    if (retvalue==NO) 
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:throwmessage delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [alert show];
        [alert release];       
    }
    return  retvalue;
    
}   






Check 0r call this function When Required

Such AS

-(IBAction)Save{

if([self validateinput]){


}
else{



}

Thursday, May 24, 2012

A Quick Guide For NSUserDefaults

Here is a quick reference for some of the things you can do with NSUserDefaults
Saving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving an NSString
[prefs setObject:@"TextToSave" forKey:@"keyToLookupString"];
// saving an NSInteger
[prefs setInteger:42 forKey:@"integerKey"];
// saving a Double
[prefs setDouble:3.1415 forKey:@"doubleKey"];
// saving a Float
[prefs setFloat:1.2345678 forKey:@"floatKey"];
// This is suggested to synch prefs, but is not needed (I didn't put it in my tut)
[prefs synchronize];
Retrieving
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSString
NSString *myString = [prefs stringForKey:@"keyToLookupString"];
// getting an NSInteger
NSInteger myInt = [prefs integerForKey:@"integerKey"];
// getting an Float
float myFloat = [prefs floatForKey:@"floatKey"];

Monday, May 21, 2012

Adding textField in UIAlertView

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

[myAlert addTextFieldWithValue:@"" label:@"name-age"];
myTextField = [myAlert textFieldAtIndex:0];
myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
myTextField.keyboardType = UIKeyboardTypeAlphabet;
myTextField.keyboardAppearance = UIKeyboardAppearanceAlert;
myTextField.autocapitalizationType  = UITextAutocapitalizationTypeWords;
myTextField.autocorrectionType = UITextAutocapitalizationTypeNone;
myTextField.textAlignment = UITextAlignmentCenter;

[myAlert show];
[myAlert release];

Thursday, May 17, 2012

How to Change the AlertView backround

       


       UIImage *theImage = [UIImage imageNamed:@"alert.png"];    
       theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
        CGSize theSize = [deletealert frame].size;
        
        UIGraphicsBeginImageContext(theSize);    
        [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
        theImage = UIGraphicsGetImageFromCurrentImageContext();    
        UIGraphicsEndImageContext();
        
        [[deletealert layer] setContents:[theImage CGImage]];
        [deletealert release];
        
        

Email validation in iphone

- (BOOL) isValidEmail:(NSString *) email {
errorMessage = [NSMutableString stringWithString: @""];
BOOL validEmail = YES;
NSString *emailRegex = @"[a-zA-Z0-9.\\-_]{2,32}@[a-zA-Z0-9.\\-_]{2,32}\[A-Za-z]{2,4}";
NSPredicate *regExPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
validEmail = [regExPredicate evaluateWithObject:email];
if (!validEmail) {
errorMessage = [NSMutableString stringWithString:@"Invalid Email"];
        validEmail = NO;
        NSLog(@"Invalid Email");
}
if ([email length] > 30) {
errorMessage = [NSMutableString stringWithString:@"Very Long Email"];
validEmail = NO;
        NSLog(@"Very Long Email");
}
if ([email length] == ZERO_LENGTH) {
errorMessage = [NSMutableString stringWithString:@"Please type valid email id"];
validEmail = NO;
        NSLog(@"Please type valid email id");
}
return validEmail;
}

Monday, May 14, 2012

JSON web Services in Iphone


JSON is nothing but java web service. We will make rest call to invoke the JSON web services. To parse the data, we should import JSON classes in our application. We can parse the result in connectionDidFinishLoading method. We will see one small example to analyze the parsing function using JSON parser.

9.2  JSON Parsing with Example

         We have to start with Xcode and create a view based application. Now, we have to add JSON classes in to our application, for that right click on the application name and choose Add Files. After adding the Files application will be look as follows,





         You can see  JSON classes in the left pane of Xcode window. Now come back to the header section and import JSON.h file in it.  We have to define UILabel to print the result and NSMutableData to get the result from service. To invoke the action, we have to declare one action in the header section, finally header file will be look as follows,








         Now come to implementation section and define the action.We have to implement the connection for result data in the connection delegates. The code will look as follows,



        
         In connection finish loading file we have to parse data. Here, data will be get as dictionary format, so we have to get desire result by using the keys as follows,



        
         We will get the response data and we have to convert that encoded data as string by using NSUTF8 encoding method. Then we have to store the parse result in one array, for that purpose we  are using latest loans array by getting the JSON value for string.
         Connect the actions and outlets in the xib and build and run the application. We will get the output as follows,









 
Loading