ITeye博客

联系人分组

caoyudong · 2014-12-31 11:31 · 移动开发 · Markdown

url:http://mobile.9sssd.com/ios/art/967

#import <UIKit/UIKit.h> 2 @interface HomeViewController : UIViewController 3 <UITableViewDelegate, UITableViewDataSource>{ 4 } 5 @property (nonatomic, retain) NSDictionary *contactTitles;//存储所有的联系人信息 6 @property (nonatomic, retain) NSArray *groups;//所有分类名称存入数组中 7 @end 3. HomeViewController.m中添加代码

View Row Code 1 #import "HomeViewController.h" 2 @interface HomeViewController () 3 @end 4 @implementation HomeViewController 5 @synthesize contactTitles; 6 @synthesize groups; 7 - (void)viewDidLoad 8 { 9
10 NSString *path = pathForResource:@"contacts" ofType:@"plist"];//plist文件路径 11 NSDictionary *dict = initWithContentsOfFile:path]; 12 self.contactTitles = dict; 13 ; 14
15 NSArray *array = sortedArrayUsingSelector:@selector(compare:)]; 16
17 self.groups = array; 18 ; 19 } 20 //使用UITableViewDataSource协议的tableView:cellForRowAtIndexPath:方法 21 - (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 22
23 static NSString *CellIndentifier = @"Contact"; 24
25 UITableViewCell *cell = ; 26
27 if (cell == nil) { 28 cell = initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier] autorelease]; 29
30 } 31
32
33 NSString *group = ]; 34 NSArray * contactSection = ; 35 cell.textLabel.text = ]; 36
37
38 //单元格添加图片 39 UIImage *image = ; 40 cell.imageView.image = image; 41
42
43 return cell; 44 } 45 - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{ 46 return ; 47 } 48 //使用UITableViewDataSource协议的tableView:numberOfRowsInSection:方法 49 //该方法用来设置Table View中要显示数据的行数 50 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 51 52 NSString *group = ; 53 NSArray *contactSection = ; 54
55 return ; 56 } 57 //添加标题和脚本信息 58 - (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 59 NSString *group = ; 60 return group; 61
62 } 63 - (NSString *)tableView:(UITableView )tableView titleForFooterInSection:(NSInteger)section{ 64 return @"作者:what if"; 65 } 66 67 68 ///UITableViewDelegate协议的方法,选择表格中的项目 69 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 70 NSString *contactSelected = ]; 71 NSString *msg = initWithFormat:@"您选择的联系人:%@", contactSelected]; 72 UIAlertView *alert = initWithTitle:@"选择联系人" message:msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 73 ; 74 ; 75 ; 76 ; 77 } / 78 / 79 //UITableViewDelegate协议的方法,表格中的缩进 80 - (NSInteger) tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath )indexPath{ 81 return % 9; 82
83 }
/ 84 //索引功能 85 86 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{ 87 return groups; 88 } 89 //用户点击标志后触发的事件,只有DetailDisclosure Button才有该事件 90 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ 91 //进入到该项目的详细信息页面 92 }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。