/*------------------------如下爲UITableViewDataSource代理方法------------------------*/spa
//加載loadView,以後先返回section,再返回row,在設置row高度,最後繪製cell代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionit
{io
return [_aa count];table
}ast
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathclass
{object
static NSString *celID = @"cell";sso
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:celID];queue
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];