自定义tableview

iOS 码拜 9年前 (2015-05-08) 668次浏览 0个评论
 

我在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,但是用不好,有会或者出现过这种方法的给解决下,很急,谢谢了!

10分
那不叫自定义
应该继承UITableViewCell,然后重写里面的内容,在委托中定义高度
我重新自定义了一遍,但是实现了想要的效果但是图片老是会自动变!因为我点击button会变换图片以示点击过了, 当我点击一个之后下拉,下面有的没有点击的button图片也会变
顶一下把,很急!老是点击一个button下拉的时候后面总是有button变成点击之后的图片,但是我打印出来看了下,就只图片变了,其实没有点击过!应该是重叠的问题,有会的或者遇到过的解决下,谢谢了!
我在cell加的一个button,点击之后会变图片,我tableview每页显示5条数据,我点击第一条的button改变之后,下拉之后,每隔5隔cell之后他的图片都会变,有遇到的或者会的帮忙解决下!
30分
搞面向对象的,看着你的这些代码应该很难受,呵。楼上说了,应该把你的cell的实现放到继承UITableViewCell的类里。一个cell,一个你继承下来的类的实例。这样做的话想出现你说的问题都难,呵。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明自定义tableview
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!