/*------------------------以下为UITableViewDataSource代理方法------------------------*/
//加载loadView,之后先返回section,再返回row,在设置row高度,最后绘制cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_aa count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *celID = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celID];
if (cell==nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:celID] autorelease];
UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 600, 60)];
lable.tag = 101;
//lable.backgroundColor = [UIColor blueColor];
[cell.contentView addSubview:lable];
[lable release];
}
UILabel *lable = (UILabel*)[cell.contentView viewWithTag:101];
lable.text = [self.aa objectAtIndex:indexPath.row];
lable.textColor = [UIColor redColor];
lable.font = [UIFont systemFontOfSize:28];
lable.numberOfLines = 0;
// cell.textLabel.text = [self.aa objectAtIndex:indexPath.row];
// cell.textLabel.textColor = [UIColor redColor];
// cell.textLabel.font = [UIFont systemFontOfSize:28];
// cell.textLabel.numberOfLines = 0; // 解除row的限制
if (_path.row==indexPath.row) {
cell.accessoryType =1;
//NSLog(@"当前的风格为----%d",cell.accessoryType);//这里不知道为什么有时候会是1,有时候会是0,感觉有点像交替的
}else{
cell.accessoryType =0;
}
NSLog(@"row为: %d",indexPath.row);
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
/*------------------------以下为UITableView代理方法------------------------*/
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath //设置row高
{
NSString *text = [_aa objectAtIndex:indexPath.row]; //UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];//错误的写法
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:28] constrainedToSize:CGSizeMake(768, 1024)];
return size.height+36;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"现在选中了row为: %d",indexPath.row);
UITableViewCell *lastCell = [tableView cellForRowAtIndexPath:_path];
lastCell.accessoryType = 0;
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = 1;
_path = [indexPath retain];