Wednesday, 20 April 2011

UINavigationController Programmatically





 //navigAppdelegate.h
#import <UIKit/UIKit.h>
@class RootViewController;
@interface navigAppDelegate : NSObject <UIApplicationDelegate>
 {
   UIWindow *window;
   UINavigationController *navigationController;
    RootViewController *viewcontroller;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet RootViewController *viewcontroller;
@end





//navigAppdelegate.m

#import "navigAppDelegate.h"
#import "RootViewController.h"
@implementation navigAppDelegate
@synthesize window;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
 {
RootViewController *mainMenuVC = [[RootViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];         [self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
[mainMenuVC release];
}
- (void)dealloc
 {
    [navigationController release];
    [window release];
    [super dealloc];
}
@end


#import <UIKit/UIKit.h>

@class first;

@class second;

@class third;

@interface RootViewController : UITableViewController
 {
   
first *view1;
   
second *view2;
   
third *view3;

}
@property (nonatomic, retain) IBOutlet first *view1;

@property (nonatomic, retain) IBOutlet second *view2;

@property (nonatomic, retain) IBOutlet third *view3;

@end





//RootViewController.m

#import "navigAppDelegate.h"
#import "RootViewController.h"
@implementation navigAppDelegate
@synthesize window;
@synthesize navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {   
 RootViewController *mainMenuVC = [[RootViewController alloc] init];
 navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];   [self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
 return YES; 
[mainMenuVC release];
}
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {
 
 return 1;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
 
 return 3;

}

- (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] autorelease];

    }
      
if((indexPath.row ) == 0)
  

[cell setText:@"Green"];
  
if((indexPath.row ) == 1)
  
[cell setText:@"Blue"];
 
  if((indexPath.row ) == 2)
 
 [cell setText:@"Magenta"];
  
return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  


    if((indexPath.row ) == 0)
  
{
      
view1 = [[first alloc] init];
 
 [self.navigationController presentModalViewController:dvc1 animated:YES];

    [view1 release];

    }
  
if((indexPath.row)==1)
  
{
  
view2=[[second alloc]init];

    [self.navigationController presentModalViewController:dvc2 animated:YES];
  
[view2 release];
  
}
  
if((indexPath.row)==2)
  
{
      
view3=[[third alloc]init];
  
    [self.navigationController presentModalViewController:dvc3 animated:YES];
  
    [view3 release];
    }
  

}


- (void)dealloc
 {
    [navigationController release];
    [window release];
    [super dealloc];
}
@end








Friday, 15 April 2011

Finding all possible combinations of a string in c

In this Program we are going to find all the possible combinations of a given string....
Example output:
Enter the String:123
The possible Strings are
132
123
213
312
231
321

#include<stdio.h>
#include<conio.h>
#include<string.h>
void swap(int ,int);
char temp,a[20],b[20],c[20];
int h,e,l,z,i=0,j=1;
void main()
{
clrscr();
printf("Enter the string:\n");
gets(a);
l=strlen(a);
for(i=0;a[i]!='\0';i++)
{
b[i]=a[i];
c[i]=a[i];
}
i=0;
swap(i,j);
getch();
}
void swap(i,j)
{
while(z<l)
{
if(i==z)
{
if(z==l-1)
{
i=0;j=1;
}
else if(z==l-2)
{
i=z+1;j=0;
}
else
{
i++;
j=i+1;
}
}
if(j==z)
{
if(z==l-1)
j=0;
else
j++;
}
temp=a[i];
a[i]=a[j];
a[j]=temp;
puts(a);
i++;
j++;
if(j==l)
j=0;
if(i==l)
i=0;
e=strcmp(a,c);
if(e==0)
{
for(i=0;a[i]!='\0';i++)
a[i]=b[i];
h=0;
z++;
temp=a[h];
a[h]=a[z];
a[z]=temp;
puts(a);
for(i=0;a[i]!='\0';i++)
c[i]=a[i];
i=0;j=1;
}
}
}

Adding an event to UIImageView Programmatically



-Now we are going to add an event to the UIImage
-By using the UITapGestureRecognizer we can able to add the event
UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(myevent:)] autorelease]; 
-Here the myevent is the function which is called after the event has occured
[image addGestureRecognizer:tapGesture];
-Set the userInteraction 
[image setUserInteractionEnabled:YES];