当前位置: 代码迷 >> Iphone >> 自定义tableview解决思路
  详细解决方案

自定义tableview解决思路

热度:156   发布时间:2016-04-25 06:49:03.0
自定义tableview
我在tableview的cell里面加了个label和button,我想实现我点击了哪个button就可以找到对应的label上面的值,我是这样添加的! if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
reuseIdentifier: SimpleTableIdentifier ] autorelease];


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(288, 10, 29, 29)];
[button setImage:[UIImage imageNamed:@"Unselected.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(imageButt:)
forControlEvents:UIControlEventTouchUpInside];
// [button setTag:(int *)row];
[cell.contentView addSubview:button];
// [button release];

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 280, 30)];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setTag:1];
[cell.contentView addSubview:label];
[label release];
}
UILabel *textName=(UILabel *)[cell.contentView viewWithTag:1];
[textName setText:[array objectAtIndex:row]];

尝试过用tag,但是用不好,有会或者出现过这种方法的给解决下,很急,谢谢了!!

------解决方案--------------------
那不叫自定义
应该继承UITableViewCell,然后重写里面的内容,在委托中定义高度
------解决方案--------------------
搞面向对象的,看着你的这些代码应该很难受,呵。楼上说了,应该把你的cell的实现放到继承UITableViewCell的类里。一个cell,一个你继承下来的类的实例。这样做的话想出现你说的问题都难,呵。
  相关解决方案