iam构建一个应用程序,其中iam在UITable视图单元的单行中显示5个小图像。我想在每个图像上选择行,而不是选择行。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 160;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"simpsons"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"simpsons"] autorelease];
}
//cell.textLabel.text = [theSimpsons objectAtIndex:indexPath.row];
//NSString *imageName = [NSString stringWithFormat:@"%d.png", indexPath.row];
//cell.imageView.image = [UIImage imageNamed:imageName];
image1= [[UIImageView alloc] initWithFrame:CGRectMake(5.0,10.0,78, 74)];
[cell.contentView addSubview:image1];
image1.image = [UIImage imageNamed:@"0.png"];
image2= [[UIImageView alloc] initWithFrame:CGRectMake(80.0,10.0,78, 74)];
[cell.contentView addSubview:image2];
image2.image = [UIImage imageNamed:@"1.png"];
image3= [[UIImageView alloc] initWithFrame:CGRectMake(170.0,10.0,78, 74)];
[cell.contentView addSubview:image3];
image3.image = [UIImage imageNamed:@"2.png"];
image4= [[UIImageView alloc] initWithFrame:CGRectMake(240.0,10.0,78, 74)];
[cell.contentView addSubview:image4];
image4.image = [UIImage imageNamed:@"3.png"];
return cell;
}
我想在每个图像选择上只打开一个新行,而不是在行上点击?????
答案 0 :(得分:0)
使用UIImageView.Use UIButton.In自定义样式的内容...并在UIButton背景中放置图像,最后您的图像将出现,当您单击按钮时,您的TableRow未被选中。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImage *Image=[UIImage imageNamed:@"QuickSearchImage.png"];
static NSString *identifier = @"Cell";
UIColor *txtCol=[UIColor clearColor];
UIColor *ButtonTextCol=[UIColor whiteColor];
NSString *FontName=@"verdana";
int FontSize=12;
CGRect frame ;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
for (UIView *subview in subviews) {
[subview removeFromSuperview];
}
[subviews release];
cell=nil;
if(cell == nil)
{
CGRect cellRectangle;
cellRectangle = CGRectMake(0.0, 0.0, 1024, 200);
cell = [[[UITableViewCell alloc] initWithFrame:cellRectangle reuseIdentifier:identifier] autorelease];
UIButton *button ;
frame = CGRectMake(XOFFSET, YOFFSET, COLWIDTH, COLHEIGHT);
button = [[UIButton alloc] initWithFrame:frame];
//[button addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside];
[button setTag:1000];
[cell.contentView addSubview:button];
[button release];
}
}
UIButton *BtnCol = (UIButton *)[cell viewWithTag:COLTAG];
[BtnCol setTag:COLTAG];
[BtnCol setTitle:[ArrCol objectAtIndex:IntIndex] forState:UIControlStateNormal];
[BtnCol setTitleColor:ButtonTextCol forState:UIControlStateNormal];
[BtnCol setBackgroundImage:Image forState:UIControlStateNormal];
BtnCol.titleLabel.font=[UIFont fontWithName:FontName size:FontSize];
return cell;
}
答案 1 :(得分:0)
不确定
1:您可以使用按钮(显示图像和可点击)以及其他控件来自定义单元格。 然后在单元格中设置每个按钮的标记。
2:在每个按钮的IBAction事件中,记录标签并使用委托选择相关行。