ipad开发对表格视图的基本实现


#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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值