Есть ли способ переместить строку в выбранную строку в UITableView на изображение, а не на выбор строки - PullRequest
0 голосов
/ 30 июня 2010

Я создаю приложение, в котором я показываю 5 маленьких изображений в одной строке ячейки представления UITable.Я хочу сделать выбор строки на каждом изображении, щелкнув не по выбору строки.

- (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;
 }

Я хочу, чтобы на каждом изображении выбиралась только новая строка, которую мы будем открывать, а не на щелчке строки ?????

Ответы [ 2 ]

0 голосов
/ 03 декабря 2012

Конечно.

1: вы можете настроить ячейку с помощью кнопки (показать изображение и кликабельность) и других элементов управления. Затем установите тег каждой кнопки в ячейке.

2: В событии IBAction каждой кнопки запишите тег и используйте делегат для выбора соответствующей строки.

0 голосов
/ 08 июня 2011

Нередко использование UIImageView.Use UIButton.In Custom Style. И поместите изображение в фон 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;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...