UITableViewCell 预习

2016-02-24  本文已影响24人  雷仔

@property (nonatomic, retain)NSMutableArray *arr;

@property (nonatomic, retain)UITableView *tbv;

@end

@implementation RootViewController

- (void)dealloc

{

[_arr release];

[_tbv release];

[super dealloc];

}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {

self.arr = [NSMutableArray arrayWithObjects:@"大鸭梨", @"小压力", @"大大鸭梨", @"小小鸭梨", @"大小鸭梨", @"超级鸭梨", nil];

}

return self;

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor lightGrayColor];

self.navigationController.navigationBar.translucent = NO;

self.navigationItem.title = @"鸭梨大";

self.tbv = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStyleGrouped];

self.tbv.backgroundColor = [UIColor whiteColor];

[self.view addSubview:self.tbv];

[self.tbv release];

self.tbv.rowHeight = 100;

self.tbv.delegate = self;

self.tbv.dataSource = self;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return self.arr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *reuse = @"reuse";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];

if (!cell) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse] autorelease];

}

cell.textLabel.text = self.arr[indexPath.row];

cell.imageView.image = [UIImage imageNamed:@"S1.jpg"];

cell.detailTextLabel.text = @"detail";

cell.accessoryType = UITableViewCellAccessoryDetailButton;

return cell;

}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

NSLog(@"section = %ld, row = %ld", indexPath.section, indexPath.row);

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

[tableView deselectRowAtIndexPath:indexPath animated:YES];

DetailViewController *DeVC = [[DetailViewController alloc] init];

DeVC.indexPath = indexPath;

[self.navigationController pushViewController:DeVC animated:YES];

[DeVC release];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

return 3;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navig

上一篇下一篇

猜你喜欢

热点阅读