Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can icon on UITableViewAccessory replace?

i have a table view, in one condition i want to use an accessory using UITableViewCellAccessoryDetailDisclosureButton, but i want to change that icon with my icon, can i do it??

like image 532
R. Dewi Avatar asked Dec 02 '25 20:12

R. Dewi


1 Answers

yes ....you can do it easily by adding custom button...

  1. Create the Custom button,
  2. Setting the image of button
  3. Add this button to accessoryView
  4. Set the method for the button

I am providing you some help with the Code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
   cell =(Custom *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[Custom alloc]  initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        [cell setBackgroundColor:[UIColor clearColor]];
        menuTable.separatorColor =[UIColor clearColor];

    }
    UIImage *image = [UIImage imageNamed:@"ButtonClickOrder.png"];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
    button.frame = frame;   // match the button's size with the image size

    //[button setBackgroundImage:image forState:UIControlStateNormal];
    [button setImage:image forState:UIControlStateNormal];
    // set the button's target to this table view controller so we can interpret touch events and map that to a NSIndexSet
    [button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    cell.accessoryView = button;

       return cell;
}

//These are the methods which are called with the AccessoryView is Clicked

- (void)checkButtonTapped:(id)sender event:(id)event
{

    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:menuTable];
    NSIndexPath *indexPath = [menuTable indexPathForRowAtPoint: currentTouchPosition];
    NSLog(@"Section:%d",indexPath.section);
    NSLog(@"Index:%d",indexPath.row);
    if (indexPath != nil)
    {
         [ self tableView: menuTable accessoryButtonTappedForRowWithIndexPath: indexPath];

    }

}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{   

        NSLog(@"%d",indexPath.section);

}

Hope this will surely work for u....

like image 145
Ajay Sharma Avatar answered Dec 04 '25 12:12

Ajay Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!