#import "RootViewController.h"
@implementation RootViewController
@synthesize contactInformationViewController;
//定义表格中的数据集合
NSMutableArray *listOfContacts;
//当窗口加载完成初始化数据集合的内容
- (void)viewDidLoad {
[super viewDidLoad];
listOfContacts = [[NSMutableArray alloc] init];
[listOfContacts addObject:@"张三"];
[listOfContacts addObject:@"李四"];
self.navigationItem.title = @"联系人";
[super viewDidLoad];
}
//只有一组列表显示如果显示,返回值为组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
//关键方法,返回当前列表一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [listOfContacts count];
}
//定义表格中的每一行显示的内容,在这里假如nslog 就可以知道运行原理了
- (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] autorelease];
}
cell.textLabel.font = [UIFont systemFontOfSize:17];
NSString *cellValue = [listOfContacts objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
//实现选中某一行的事件处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
NSString *contactName = [listOfContacts objectAtIndex:row];
if (self.contactInformationViewController == nil) { //创建一共弹出窗口
ContactInformationViewController *c = [[ContactInformationViewController alloc]
initWithNibName:@"ContactInformationView"
bundle:[NSBundle mainBundle]];
self.contactInformationViewController = c;
[c release];
}
[self.contactInformationViewController initWithContactName:contactName];
//弹出窗口
[self.navigationController pushViewController:self.contactInformationViewController
animated:YES];
}
- (void)dealloc {
[listOfContacts release];
[super dealloc];
}
@end
2

被折叠的 条评论
为什么被折叠?



