Showing posts with label Objective C Code. Show all posts
Showing posts with label Objective C Code. Show all posts

Friday, 9 November 2012

Iphone developer technical Task : Enhancements in the App

Here is a simple Unit converter App.
Description : If you Enter any integer in the textfields,it gives the conversions as per the mentioned format.

So the actual task goes here..

It needs few enhancements that can be implemented with some additional piece of logic.
Find out where the App is lacking the behaviour of unit Conversion interms of UI(user interface) and implement them.

For your reference the actual code:

unitConverter.h


#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate>
{
IBOutlet UITextField *txt1;
IBOutlet UITextField *txt2;
IBOutlet UITextField *txt3;
IBOutlet UITextField *txt4;
IBOutlet UIButton *btn;

}

-(IBAction)showValues:(id)sender;
@end

unitConverter.m


-(IBAction)showValues:(id)sender
{

if ([txt2 isFirstResponder])
{

NSString *inputString = [[NSString alloc]initWithFormat:txt2.text];
int value = [inputString intValue];
NSLog(@"%x",value);
txt3.text=[NSString stringWithFormat:@"%x", value];
txt2.text=[NSString stringWithFormat:@"%o", value];
txt4.text=[NSString stringWithFormat:@"%d", value];
}


else if ([txt3 isFirstResponder])
{

NSString *inputString = [[NSString alloc]initWithFormat:txt3.text];
int value = [inputString intValue];
NSLog(@"%x",value);
txt3.text=[NSString stringWithFormat:@"%x", value];
txt2.text=[NSString stringWithFormat:@"%o", value];
txt4.text=[NSString stringWithFormat:@"%d", value]; }

else if ([txt4 isFirstResponder])
{

NSString *inputString = [[NSString alloc]initWithFormat:txt4.text];
int value = [inputString intValue];
NSLog(@"%x",value);
txt3.text=[NSString stringWithFormat:@"%x", value];
txt2.text=[NSString stringWithFormat:@"%o", value];
txt4.text=[NSString stringWithFormat:@"%d", value];
}

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}

ScreenShots for your understanding.



Note : Please do Mapping in the xib file inorder to make the app work in the device or simulator.As there is a delegate for the textField (hide keypad) make sure that you do reverse mapping for the delegate to the file's owner.




Thursday, 14 June 2012

Sample Project on Objective C---BODY MASS INDEX(BMI)

Application overview in Iphone.


Get the complete application code and documentation at
http://www.iosbricks.blogspot.in/

Saturday, 19 May 2012

App Level Notification for Iphone SDK

AppLevelNotification:




AppDelegate.h:----
#import

@class Animations2ViewController;

@interface Animations2AppDelegate : NSObject {
UIWindow *window;
Animations2ViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Animations2ViewController *viewController;
-(void)appdelegateNotificationRecieved;
@end
AppDelegate.m:----
#import "Animations2AppDelegate.h"
#import "Animations2ViewController.h"

@implementation Animations2AppDelegate

@synthesize window;
@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[[NSNotificationCenter defaultCenter]addObserver:viewController selector:@selector(notificationRecieved) name:@"maheshWokeUp" object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(appdelegateNotificationRecieved) name:@"maheshWokeUp" object:nil];
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];

return YES;
}
-(void)appdelegateNotificationRecieved{

NSLog(@"Appdelegate notificationr received");
}

- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}


@end


Animations2ViewController.h:----

#import

@interface Animations2ViewController : UIViewController {

IBOutlet UIImageView *imgView;
IBOutlet UIButton *btn1;
IBOutlet UIButton *btn2;
}
-(IBAction)startAnimating;
-(IBAction)stopAnimating;
-(void)notificationRecieved;
@end


Animations2ViewController.m:----

#import "Animations2ViewController.h"

@implementation Animations2ViewController

-(void)notificationRecieved{

NSLog(@"notification recieved");
}

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{

NSLog(@"device moved");
}

-(IBAction)startAnimating{

[imgView startAnimating];
}
-(IBAction)stopAnimating{

[[NSNotificationCenter defaultCenter]postNotificationName:@"maheshWokeUp" object:nil];

}


- (void)viewDidLoad {
[super viewDidLoad];


UIImage *img1= [UIImage imageNamed:@"1.jpg"];
UIImage *img2= [UIImage imageNamed:@"2-1.jpg"];
UIImage *img3= [UIImage imageNamed:@"2.jpg"];
UIImage *img4= [UIImage imageNamed:@"3.jpg"];

NSArray *arrImages =[[NSArray alloc]initWithObjects:img1,img2,img3,img4,nil];
imgView.animationImages =arrImages;
imgView.animationDuration =10;
}

- (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.
}

- (void)viewDidUnload {
}


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

@end



Objective C Program For Animations In IPHONE

Animations program:


AppDelegate.h:----
#import <UIKit/UIKit.h>

@class Animations2ViewController;

@interface Animations2AppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    Animations2ViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Animations2ViewController *viewController;
@end
AppDelegate.m:----
#import "Animations2AppDelegate.h"
#import "Animations2ViewController.h"

@implementation Animations2AppDelegate

@synthesize window;
@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
   
     // Override point for customization after app launch   
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
   
    return YES;
}


- (void)dealloc {
    [viewController release];
    [window release];
    [super dealloc];
}


@end





Animations2ViewController.h:----

#import <UIKit/UIKit.h>

@interface Animations2ViewController : UIViewController<UIAccelerometerDelegate> {

    IBOutlet UIImageView *imgView;
    IBOutlet UIButton *btn1;
    IBOutlet UIButton *btn2;
}
-(IBAction)startAnimating;
-(IBAction)stopAnimating;
@end


Animations2ViewController.m:----

#import "Animations2ViewController.h"

@implementation Animations2ViewController

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{

    NSLog(@"device moved");
}

-(IBAction)startAnimating{

    [imgView startAnimating];
}
-(IBAction)stopAnimating{

    [UIView beginAnimations:@"animation1" context:nil];
    [UIView  setAnimationCurve:UIViewAnimationCurveLinear];

    [UIView setAnimationDuration:10];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:btn2 cache:YES];
    btn1.frame =CGRectMake(100, 300, 60, 40);
    [UIView commitAnimations];

    }


- (void)viewDidLoad {
    [super viewDidLoad];
   
   
    UIImage *img1= [UIImage imageNamed:@"1.jpg"];
    UIImage *img2= [UIImage imageNamed:@"2-1.jpg"];
    UIImage *img3= [UIImage imageNamed:@"2.jpg"];
    UIImage *img4= [UIImage imageNamed:@"3.jpg"];
   
    NSArray *arrImages =[[NSArray alloc]initWithObjects:img1,img2,img3,img4,nil];
    imgView.animationImages =arrImages;
    imgView.animationDuration =10;
}

- (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.
}

- (void)viewDidUnload {
    }


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

@end