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

UIImageView Programmatically (Tutorial)





UIImageView Programmatically

      Now We are going to create UIImageView Programmatically Without using Interface builder.

In .h file 
-Declare this
IBOutlet UIImageView *image;

In .m file
UIImage *image1=[UIImage imageNamed:@name.jpg"];
image=[[UIImageview alloc]initWithImage:image1];
-set the view size for the image
image.frame=CGRectMake(0,0,320,400);
-Add the image to the view
[self.view addSubview:image];
-release the image
[image release];
To Add an event to this Image

Wednesday 6 April 2011

UIScrollView Programmatically(Horizontal Scroll)

      With the help of  the UIScrollView class we can able to  display content that is larger than the size of the application’s window. It enables users to scroll the view and to see the full contents.

       Now we are going to create the UIScrollView Programmatically without using Interface Builder.

-creating the scroll view

UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
 
-now we are going to create the views which are going to display in the scrollview.
-We are going to create 4 views.

-we are going to scroll that 4 views Horizontally.


    NSInteger viewcount= 4;
    for (int i = 0; i <viewcount; i++) 

   {
    CGFloat y = i * self.view.frame.size.width;
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(x, 0, self.view.frame.size.width,           self.view.frame.size.height)];
    view.backgroundColor = [UIColor greenColor];
    [scrollview addSubview:view];
    [view release];
    }

-x will place every UIView exactly where the previous UIView has stopped.
-The x and y coordinates for creating the new 4 views are.
-(0,0)(320,0)(640,0)(960,0)
-We are increasing the x coordinate only, so we can able to add the views horizontally one after other.

-Set the UIScrollView contentSize

scrollview.contentSize = CGSizeMake(self.view.frame.size.width * viewcount, self.view.frame.size.height);
 
-ContentSize is nothing, it is size of the total view(Total size of 4 views)
-Here the content size is(1280,480)

Tutorial for UIScrollView Programmatically (Vertical Scroll)


      With the help of  the UIScrollView class we can able to  display content that is larger than the size of the application’s window. It enables users to scroll the view and to see the full contents.





-Now we are going to create the UIScrollView Programmatically without using Interface Builder.

-creating the scroll view
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
 
-now we are going to create the views which are going to display in the scrollview.
-We are going to create 4 views.
-we are going to scroll that 4 views vertically.
NSInteger viewcount= 4; 
for (int i = 0; i <viewcount; i++) 
{ 
CGFloat y = i * self.view.frame.size.height; 
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, y,                                                      self.view.frame.size.width, self .view.frame.size.height)];      
view.backgroundColor = [UIColor greenColor]; 
[scrollview addSubview:view]; 
[view release]; 
}
-y will place every UIView exactly where the previous UIView has stopped.
-The x and y coordinates for creating the new 4 views are.
-(0,0)(0,460)(0,920)(0,1380)
-We are increasing the y coordinate only, so we can able to add the views vertically one after other.
-Set the UIScrollView contentSize
scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *viewcount);
 
- ContentSize is nothing, it is size of the total view(Total size of 4 views)
-Here the content size is(320,1840)
You may also like
UINavigationController Programmatically
Adding an event to an UIImage





Tuesday 15 March 2011

"Hello world program without using semi-colon"

#include
void main()
{
if(printf("Hello world"))
{
}
}
Run the program
To see the result press ALT + F5
OUTPUT