[英]How to create custom buttons in custom tableCell in each cell i need three images
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
HomeVCTableViewCell *cell = (HomeVCTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[HomeVCTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
int imageNumber = 0;
for (int i = (indexPath.row * imagesCount); i < ((indexPath.row *imagesCount) + imagesCount); i++) {
if (i < [cellImageVOArray count]) { // If resultsArray Count is odd then we no need to create cell image
PhotoVO *photoVo = (PhotoVO *)[cellImageVOArray objectAtIndex:i];
cell.photobutton.frame=CGRectMake(((imageNumber * 5)+5)+(imageNumber * width), 2, width, height -4);
cell.photobutton.tag = i + 100;
[[cell.photobutton layer] setBorderWidth:3.0f];
[[cell.photobutton layer] setBorderColor:[UIColor whiteColor].CGColor];
[cell.photobutton addTarget:self action:@selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside];
[cell.photobutton setBackgroundImageWithURL:[NSURL URLWithString:photoVo.thumb_URL1] placeholderImage:[UIImage imageNamed:@"loader.png"]];
imageNumber ++;
}
}
return cell;
} }
CustomCell.m CustomCell.m
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
// Initialization code
NSLog(@"Content View = %f",self.contentView.frame.size.height);
photobutton=[UIButton buttonWithType:UIButtonTypeCustom];
[self.contentView addSubview:photobutton];
}
return self;
}
In the above code i got only lastbutton of the cell in every cell it was repeating please tell how to display three buttons in each cell Thanks in advance 在上面的代码中,我在每个单元格中都只有它的lastbutton重复,请告诉我如何在每个单元格中显示三个按钮
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
btn1.frame = CGRectMake(0, 0, 50, 35); // set as u required.
[self.contentView addSubview:btn1];
btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
btn2.frame = CGRectMake(65, 0, 50, 35); // set as u required.
[self.contentView addSubview:btn2];
btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
btn3.frame = CGRectMake(120, 0, 50, 25); // set as u required.
[self.contentView addSubview:btn3];
}
return self;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.