iOS开发学习之#简单通讯录的制作#
来源:互联网 发布:c语言scanf s 编辑:程序博客网 时间:2024/05/16 19:14
(1)创建一个项目telephoneBook
(2)打开Main.storyboard文件,从视图库图拖一个Tab bar Controller标签栏控制器到画布中。
(3)在工具栏中,选择show the Attributes inspector图标,在View controller下,选择Is Initial View Controller。
(4)将画布中的原有的view controller视图控制器删掉,再将Tab Bar controller标签栏控制器关联view controller-Item 1和view controller-Item2视图控制器的视图删除。
(5)从视图库中拖一个Navigation controller导航控制器到画布中。
(6)将Tab Bar Controller标签栏控制器关联视图变为Navigation Controller导航控制器。
核心代码:
TableView1.h
#import <UIKit/UIKit.h>@interface TableView1 : UITableViewController<UITableViewDataSource,UITableViewDelegate>{ NSMutableArray *a;}- (IBAction)aa:(id)sender;- (IBAction)bb:(id)sender;@end
TableView1.m
#import "TableView1.h"@interface TableView1 ()@end@implementation TableView1- (void)viewDidLoad { a = [[NSMutableArray alloc]initWithObjects:@"ant",@"alpaca",@"albatross",@"badger",@"bat",@"bear",@"cat",@"calf",@"cattle", nil]; [super viewDidLoad]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [a count];}- (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]; } cell.textLabel.text = [a objectAtIndex:[indexPath row]]; return cell;}- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [a removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }}- (IBAction)aa:(id)sender { [self setEditing:YES];}- (IBAction)bb:(id)sender { [self setEditing:NO];}@end
TableView2.h
#import <UIKit/UIKit.h>@interface TableView2 : UITableViewController<UITableViewDataSource,UITableViewDelegate>{ NSDictionary *list; NSArray *ff; IBOutlet UISearchBar *searchBar; BOOL isSearchOn; BOOL canSelectRow; NSMutableArray *listOfMovies; NSMutableArray *searchResult;}- (void)searchMoviesTableView;@end
TableView2.m
#import "TableView2.h"@interface TableView2 ()@end@implementation TableView2- (void)viewDidLoad { NSString *path = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"plist"]; NSDictionary *dic = [[NSDictionary alloc]initWithContentsOfFile:path]; list = dic; NSArray *array = [[list allKeys]sortedArrayUsingSelector:@selector(compare:)]; ff = array; self.tableView.tableHeaderView = searchBar; searchBar.autocorrectionType = UITextAutocorrectionTypeYes; listOfMovies = [[NSMutableArray alloc]init]; for (NSString *year in array) { NSArray *movies = [list objectForKey:year]; for (NSString *title in movies) { [listOfMovies addObject:title]; } } searchResult = [[NSMutableArray alloc]init]; isSearchOn = NO; canSelectRow = YES; [super viewDidLoad]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (canSelectRow) { return indexPath; }else{ return nil; }}- (void)searchBar:(UISearchBar*)searchBar textDidChange:(NSString *)searchText{ if ([searchText length] > 0) { isSearchOn = YES; canSelectRow = YES; self.tableView.scrollEnabled = YES; [self searchMoviesTableView]; }else{ isSearchOn = NO; canSelectRow = NO; self.tableView.scrollEnabled = NO; } [self.tableView reloadData];}- (void)searchBarSearchButtonClicked:(UISearchBar*)searchBar{ [self searchMoviesTableView];}- (void) searchMoviesTableView{ [searchResult removeAllObjects]; for (NSString *str in listOfMovies) { NSRange titleResultRange = [str rangeOfString:searchBar.text options:NSCaseInsensitiveSearch]; if (titleResultRange.length > 0) { [searchResult addObject:str]; } }}- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if (isSearchOn) { return 1; }else{ return [ff count]; }}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (isSearchOn) { return [searchResult count]; }else{ NSString *year = [ff objectAtIndex:section]; NSArray *movieSection = [list objectForKey:year]; return [movieSection count]; }}- (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]; } if (isSearchOn) { NSString *cellValue = [searchResult objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; }else{ NSString *year = [ff objectAtIndex:[indexPath section]]; NSArray *movieSection = [list objectForKey:year]; cell.textLabel.text = [movieSection objectAtIndex:[indexPath row]]; } return cell;}- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ NSString *year = [ff objectAtIndex:section]; if (isSearchOn) { [searchBar resignFirstResponder]; return nil; }else{ return year; }}@end
0 0
- iOS开发学习之#简单通讯录的制作#
- iOS开发之通讯录
- iOS开发:通讯录之通讯录列表实现
- iOS开发之系统通讯录
- ios开发 之 通讯录操作
- iOS开发-------简单通讯录(UITableView和CoreData的应用)
- Android 多媒体开发学习之制作一个简单的画板
- 简单C语言通讯录的制作
- Android简单通讯录的开发
- iOS开发:通讯录之个人中心页面的实现
- ios开发系列之系统通讯录的相关操作
- iOS开发-------简单通讯录2(UISearchController)
- iOS开发之-----iOS如何访问通讯录
- IOS学习之——通讯录的应用
- iOS开发之静态库的制作
- iOS开发之静态库的制作
- iOS开发之简易时钟的制作
- iOS开发之.a文件的制作
- 了解传输信道的使用、传输信道特性、描述来自上层的数据在进行扩频前的处理过程、传输信道向物理信道的映射关系。
- hdu 2081 手机短号
- yymsh - 轻型的类Tcl解释器
- 各类文件的文件头标志
- MySQL的LAST_INSERT_ID用法
- iOS开发学习之#简单通讯录的制作#
- ResourceBundle和Properties
- 光学变焦与数码变焦的区别
- grep multiple strings
- 二分查找实现(Jon Bentley:90%程序员无法正确实现)
- Apache设置目录禁止访问
- 字符串组合——位运算
- Activity的启动模式以及setFlags
- table最佳设计