Tuesday, November 6, 2012

To Create UIView and Empty Xib separately Navigate one ViewController To another manualy created Xib.





For Example:

1.New file--> cocoa Touch-->objective-c class---> UIView--->give viewname. // for uiview

2.New file--> User Interface-->Empty---> iPad(or)iPhone--->give name.// xib



1.AppDelegate.h

@interface SpeedcalcAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *Toggle;

}

2.AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
Toggle=[[UINavigationController alloc]init];
[Toggle setNavigationBarHidden:YES animated:NO];
SpeedcalcViewController *test=[[SpeedcalcViewController alloc]init]; // Created ViewController
[Toggle pushViewController:test animated:NO];
[test release];
[window addSubview:Toggle.view];

}


3.ViewController.M

-(IBAction)btnnext_Clicked
{
NSLog(@"agaskjhlkasdjflas");
FmtyShareActivity *Test=[[FmtyShareActivity alloc]initWithFrame:CGRectMake(0, 0, 891, 500)]; // Assign view frame.
Test.center = self.view.center;
[self.view addSubview:Test];
}

4.Demoview.M


- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSArray *nibArray=[[NSBundle mainBundle] loadNibNamed:@"ShareActivity" owner:self options:nil]; // Xib Name
[self addSubview:[nibArray objectAtIndex:0]];
}
return self;
}


5.Manualy Created Xib

Ex:
ShareActivity.xib

Custom Class-->Class :[Demoview] // assign to custom class.



UINavigation Push one ViewController Xib to Another Xib ViewController:




1.AppDelegate.h

@interface SpeedcalcAppDelegate : NSObject <UIApplicationDelegate>
{
UINavigationController *Toggle;

}

2.AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
Toggle=[[UINavigationController alloc]init];
[Toggle setNavigationBarHidden:YES animated:NO];
SpeedcalcViewController *test=[[SpeedcalcViewController alloc]init]; // Created ViewController
[Toggle pushViewController:test animated:NO];
[test release];
[window addSubview:Toggle.view];

}

3.CreatedViewController.m

#import "SpeedcalcViewController.h"
#import "Timecalc.h" // another viewcontroller name


-(IBAction)Toggle_page
{

NSLog(@"called");
Timecalc *Toggle=[[Timecalc alloc]init];
[self.navigationController pushViewController:Toggle animated:NO];
[Timecalc release];
}


UITextFiled Email Validation:




Check if the email address accepts only the following characters.
A) Alphabets : 'A to Z' or 'a to z'
b) Numeric : 0 to 9
c)Characters !#$%&'*+-/=?^_`{|}~
c.1. Character . (dot, period, full stop) provided that it is not the first or last character, and provided also that it does not appear two or more times consecutively (e.g. John..Doe@example.com).
c.2.Special characters are allowed with restrictions including:
Space and ""(),:;<>@[\]


Code Here:

@implementation EmailvalidationViewController
@synthesize txtEmail;
@synthesize btnMail;


- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle


- (void)viewDidLoad
{
[super viewDidLoad];
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if(textField == txtEmail)
{
NSCharacterSet *invalidCharSet = [[NSCharacterSet characterSetWithCharactersInString:@".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@0123456789!#$%&'*+-/=?^_`{|}~"] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:invalidCharSet] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
static NSCharacterSet *charSet = nil;
if(!charSet) {
charSet = [[[NSCharacterSet characterSetWithCharactersInString:@"!#$%&'*+-/=?^_`{|}~"] invertedSet] retain];
}
NSRange location = [string rangeOfCharacterFromSet:charSet];
return (location.location == NSNotFound);
return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[txtEmail resignFirstResponder];
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"textFieldDidBeginEditing");
}


-(IBAction)btnMail_Clicked:(id)sender

{
NSLog(@"btnclicked");
BOOL boolValue = [self ValidateEmail:txtEmail.text];
}

-(BOOL)ValidateEmail:(NSString *)mailstring
{
NSString *mailstr = txtEmail.text;
NSRange openingRange = [mailstr rangeOfString:@".."];
if (openingRange.location!=NSNotFound)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Mail Check" message:@"Pleasesfs Enter Correct Email" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil];
[alert show];
return NO;
}
if ([mailstr hasSuffix:@"."])
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Mail Check" message:@"Please Enter Correct Email" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil];
[alert show];
return NO;
}
if ([mailstr hasPrefix:@"."])
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Mail Check" message:@"Please Enter Correct Email" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil];
[alert show];
return NO;
}
NSString *inputString = mailstr;
NSScanner *mainScanner = [NSScanner scannerWithString:inputString];
NSInteger numberOfChar=0;
while(![mainScanner isAtEnd])
{
[mainScanner scanUpToString:@"@" intoString:nil];
if(![mainScanner isAtEnd])
{
numberOfChar++;
[mainScanner scanString:@"@" intoString:nil ];
}
}
NSString *inputString1 = mailstr;
NSScanner *mainScanner1 = [NSScanner scannerWithString:inputString1];
NSInteger numberOfChar1=0;
while(![mainScanner1 isAtEnd])
{
[mainScanner1 scanUpToString:@"." intoString:nil];
if(![mainScanner1 isAtEnd])
{
numberOfChar1++;
[mainScanner1 scanString:@"." intoString:nil ];
}
}
if ((numberOfChar==1)&&(numberOfChar1 > 0))
{
NSLog(@"govings");
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""message:@"Please and check the email address."delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
return NO;
}
return YES;
}

@end