.h file
//
// DictonaryViewController.h
// Dictonary
//
// Created by santoshkumar on 29/11/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface DictonaryViewController : UIViewController<UITextFieldDelegate> {
IBOutlet UITextField *txtValue;
IBOutlet UITextField *txtKey;
NSArray *arr;
NSMutableArray *arr2;
NSMutableDictionary *dictionary;
NSDictionary *dictionary2;
IBOutlet UITextField *txtArrValue;
IBOutlet UILabel *lblArrValue;
}
-(IBAction)saveArrayValue;
-(IBAction)save;
-(IBAction)retrieveValue;
@end
.m file
//
// DictonaryViewController.m
// Dictonary
//
// Created by santoshkumar on 29/11/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//
#import "DictonaryViewController.h"
@implementation DictonaryViewController
-(IBAction)saveArrayValue{
[arr2 addObject:txtArrValue.text];
}
-(IBAction)retrieveValue{
txtValue.text = [dictionary2 valueForKey:txtKey.text];
for (int i=0; i<[arr2 count]; i++) {
lblArrValue.text = [NSString stringWithFormat:@"%@%@",lblArrValue.text, [arr2 objectAtIndex:i]];
}
}
-(IBAction)save{
//NSString *value = [NSString stringWithFormat:@"%@", txtValue.text];
[dictionary setValue:[NSMutableString stringWithFormat:@"%@",txtValue.text] forKey:txtKey.text];
txtKey.text=@"";
txtValue.text=@"";
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if (textField == txtKey) {
txtValue.text = [dictionary2 objectForKey:txtKey.text];
}
[textField resignFirstResponder];
return YES;
}
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[superviewDidLoad];
dictionary = [[NSMutableDictionary alloc]init];
txtKey.delegate =self;
txtValue.delegate = self;
dictionary2 = [[NSDictionary alloc]initWithObjectsAndKeys:@"apple",@"fruit1",@"orange",@"fruit2",@"banana",@"fruit3",nil];
arr = [[NSArray alloc]initWithObjects:@"srinu",@"rama",@"krishna",nil];
arr2= [[NSMutableArray alloc]init];
}
/*}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[superdidReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[superdealloc];
}
@end
0 comments:
Post a Comment