Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.m
- // telefon
- //
- // Created by Admin on 2014.03.06..
- // Copyright (c) 2014 __MyCompanyName__. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSString *path = [[NSBundle mainBundle] pathForResource:@"phones" ofType:@"plist"];
- allUser=[[NSArray alloc] initWithContentsOfFile:path];
- searchedUser = [[NSMutableArray alloc] init];
- NSLog(@"%@", allUser);
- UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 150, 30)];
- field.Tag=1000;
- field.borderStyle=UITextBorderStyleRoundedRect;
- field.autocorrectionType=UITextAutocorrectionTypeNo;
- field.delegate=self;
- field.autocapitalizationType=UITextAutocapitalizationTypeNone;
- [self.view addSubview:field];
- UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- button.frame=CGRectMake(170, 10, 50, 30);
- [button setTitle:@"Keres" forState:UIControlStateNormal];
- [button addTarget:self action:@selector(searchButtonClicked:) forControlEvents:UIControlEventTouchDown];
- [self.view addSubview:button];
- UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(10, 50, self.view.frame.size.width-20, self.view.frame.size.height-60)];
- tempView.tag=1001;
- tempView.backgroundColor=[UIColor grayColor];
- tempView.autoresizingMask=UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [self.view addSubview:tempView];
- }
- -(BOOL)textFieldShouldReturn:(UITextField *)textField
- {
- [self searchButtonClicked:NULL];
- [textField resignFirstResponder];
- return true;
- }
- -(void)searchButtonClicked:(UIButton *)sender
- {
- NSString *searched = ((UITextField*)[self.view viewWithTag:1000]).text;
- searched=[searched stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- if (searched.length>0)
- {
- for (NSDictionary *tempDict in allUser)
- {
- NSString *tempname=(NSString *)[tempDict objectForKey:@"name"];
- NSRange range = [tempname rangeOfString:searched options:NSCaseInsensitiveSearch];
- if (range.length > 0)
- {
- [searchedUser addObject:tempDict];
- }
- }
- }
- [self showSearchedUser];
- }
- -(void)showUserActionSheet:(UIButton *)sender
- {
- clickedUser=[searchedUser objectAtIndex:sender.tag];
- UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:[[searchedUser objectAtIndex:sender.tag] objectForKey:@"name"] delegate:self cancelButtonTitle:@"Vissza" destructiveButtonTitle:@"Törlés" otherButtonTitles:@"Mutat", nil];
- [sheet showInView:self.view];
- }
- -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- {
- switch (buttonIndex) {
- case 0:
- {
- [searchedUser removeObject:clickedUser];
- [self showSearchedUser];
- }
- break;
- case 1:
- {
- }
- break;
- default:
- break;
- }
- }
- -(void)showSearchedUser
- {
- UIView *view = [self.view viewWithTag:1001];
- for (UIView *tempbutton in [view subviews])
- {
- [tempbutton removeFromSuperview];
- }
- int i = 0;
- for (NSDictionary *dict in searchedUser)
- {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- int buttonHeight = 20;
- button.frame=CGRectMake(10, i++ * buttonHeight, view.frame.size.width-10, buttonHeight);
- [button setTitle:[dict objectForKey:@"name"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(showUserActionSheet:) forControlEvents:UIControlEventTouchDown];
- button.tag = [searchedUser indexOfObject:dict];
- [view addSubview:button];
- }
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- } else {
- return YES;
- }
- }
- @end
- .h:
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController <UITextFieldDelegate, UIActionSheetDelegate>
- {
- NSArray *allUser;
- NSMutableArray *searchedUser;
- NSDictionary *clickedUser;
- }
- -(void)searchButtonClicked:(UIButton *)sender;
- -(void)showSearchedUser;
- -(void)showUserActionSheet:(UIButton *)sender;
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement