Wednesday, November 21, 2012

Create a Global access for variable and array instead of AppDelegate declaration:





  1. Create a NSObject class
Ex:

Globalclass.h

#import <Foundation/Foundation.h>

@class Globalclass; //create a global class name

extern Globalclass *Global; // create a instance for global class


@interface Globalclass : NSObject
{
NSMutableArray *Pointarray1; // global array declaration
}

@property(nonatomic,readwrite) NSMutableArray *Pointarray1;

+(void)globalaccess; // create a class method

@end

Globalclass.m


#import "Globalclass.h"
Globalclass *Global; // create a instance for global class


@implementation Globalclass

@synthesize Pointarray1;


+(void)globalaccess
{

Global=[[Globalclass alloc]init]; // allocate global class
}

@end


ViewController.m


#import "ViewController.h"
#import "Tableview.h"
#import "Globalclass.h" // import Global class


@interface ViewController ()

@end

@implementation ViewController
@synthesize btn;


- (void)viewDidLoad
{
[Globalclass globalaccess]; // To call global class method
Global.Pointarray1=[[NSMutableArray alloc]init]; // initate the created global array
[super viewDidLoad];

}

-

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch ;
touch = [[event allTouches] anyObject];
if ([touch view] == self.view){
CGPoint location = [touch locationInView:touch.view];
UIImageView *img1=[[UIImageView alloc]init];
[img1 setImage:[UIImage imageNamed:@"bluedot.gif"]];
img1.frame=CGRectMake(2, 2,location.x,location.y);
[self.view addSubview:img1];
NSLog(@"point........ %f .. %f",location.x,location.y);
[Global.Pointarray1 addObject:[NSString stringWithFormat:@"X=%f,Y=%f",location.x,location.y]];
// To access the created array
NSLog(@"point array==>%@",Global.Pointarray1);
}
}


Tableview.m


#import "Tableview.h"
#import "Globalclass.h" // import Global class



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [Global.Pointarray1 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSString *cellValue = [Global.Pointarray1 objectAtIndex:indexPath.row]; // display the array value in table view.

cell.textLabel.text = cellValue;
return cell;
}

Monday, November 19, 2012

To Create the appDelegate variable and Access for Xcode 4.5





AppDelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSMutableArray *testArray;
}
@property(nonatomic,retain)NSMutableArray *testArray;

AppDelegate.m

@synthesize testArrayName;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
testArrayName = [[NSMutableArray alloc]init];

}


ViewController.h

#import <UIKit/UIKit.h>

@class appDelegate;

@interface ViewController : UIViewController
{
appDelegate *appdelegate;

}

ViewController.m

#import "ViewController.h"

#import “ appDelegate.h”

- (void)viewDidLoad
{
appdelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
}
To access the appdelegate varaable

Ex:

NSString *Desp=[appdelegate.arrayDescList objectAtIndex:appdelegate.objid1];


Simple NavigationController one Xib to another Xib for iOS 6.0 Simulator






AppDelegate.h

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UIWindow *window;
ViewController *viewController;
UINavigationController *navi;
}

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;

@end



AppDelegate.m

#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

@synthesize window,viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
navi=[[UINavigationController alloc]initWithRootViewController:viewController];
[navi setNavigationBarHidden:YES animated:YES];

[window addSubview:navi.view];
[self.window makeKeyAndVisible];
return YES;
}




ViewController.m

#import "ViewController.h"
#import "TableViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize btn;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

-(IBAction)btn_Clicked:(id)sender
{
NSLog(@"clicked");
TableViewController *nextView=[[TableViewController alloc]init]; // Which xib want to push
[self.navigationController pushViewController:nextView animated:YES];
}

Friday, November 9, 2012

3.Use one UIAlertView to pass the string parameter to display multiple way Alert Message//.





-(void)Show_Alert:(NSString*)strMessage
{
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:strMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}

// some method here

     if ([txtSchDate.text length]==0)
        {
            [self Show_Alert:@"Please select schedule date"];return;
        }
        if ([txtSchStartTime.text length]==0)
        {
            [self Show_Alert:@"Please select Start Time"];return;
        }
        if ([txtSchEndTime.text length]==0)
        {
            [self Show_Alert:@"Please select End Time"];return;
        }


2.Type casting UIText field using tag values assign the border color…[ Use custom UIView class]






 UITextField *txtAddressLine1Ref = (UITextField*)[self viewWithTag:4]; //txtAddressLine1
        
        txtAddressLine1Ref.layer.borderColor = [[UIColor colorWithRed:197.0f/255.0f green:215.0f/255.0f blue:224.0f/255.0f alpha:1]CGColor];
        txtAddressLine1Ref.layer.borderWidth = 1.0f;

1.How to get the subview from parent view To accès thé subview control Ex UITextview hère code






for (UIView *viewTemp in [viewContentToMoveBottom subviews]) // [self subviews]
    {
        if ([viewTemp isKindOfClass:[UITextView class]]) // which control going to check
        {
          NSLog(@"loop enter 3 ");   
            
            UITextView *txtView = (UITextView*)viewTemp;
            
            if (txtView.tag==700)
            {
                NSLog(@"loop enter1 ");
                
                txtView.layer.borderColor = [[UIColor redColor]CGColor];
                txtView.layer.borderWidth = 1.0f;
                
                
            }
            
            else
            {
                txtView.layer.borderColor = [[UIColor colorWithRed:197.0f/255.0f green:215.0f/255.0f blue:224.0f/255.0f alpha:1]CGColor];
                        txtView.layer.borderWidth = 1.0f;

            }
        }
    }

Tuesday, November 6, 2012

Flash Screen:




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect appFrame = CGRectMake(0, 0, 320, 460);

UIView *view = [[UIView alloc] initWithFrame:appFrame];
myView = view;
view.backgroundColor = [UIColor redColor];
view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
splashImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Default.png"]];
splashImgView.frame=myView.frame;
//timer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(fadeScreen) userInfo:nil repeats:NO];
[myView addSubview:splashImgView];
[self.window addSubview:myView];

}


- (void)fadeScreen
{
NSLog(@"fadeScreen");
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
//[UIView setAnimationDidStopSelector:@selector(finishedFading)];
myView.alpha = 2.0;
[UIView commitAnimations];
}