Is there a way to move row to the selected row in UITableView on image click not on row selection
iam building an application in which iam showing the 5 small images in a single row of the UITable view cell. i want to make selection of row on each image clicked not on the selection of row .
- (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 imageNam开发者_C百科ed:@"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;
}
i want on each image selection only a new row will we opened not on row click ?????
Sure.
1: you can custom a cell with a Button(show your image and clickable) and other controls. Then set the tag of each button in a cell.
2: In the IBAction event of each button, record the tag and use delegate to select relevant row.
Instad of using UIImageView.Use UIButton.In Custom Style..And Place Image In UIButton Background,So Finally Your Image Will Appear And When You Click On Button You TableRow Is Not Selected.
- (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;
}
精彩评论