значок на UITableViewAccessory можно заменить? - PullRequest
3 голосов
/ 23 ноября 2010

У меня есть табличное представление, в одном состоянии я хочу использовать аксессуар, используя UITableViewCellAccessoryDetailDisclosureButton, но я хочу изменить этот значок с помощью моего значка, могу ли я это сделать ??

1 Ответ

8 голосов
/ 23 ноября 2010

да .... вы можете сделать это легко, добавив пользовательскую кнопку ...

  1. Создать кнопку Custom,
  2. Настройка изображения кнопки
  3. Добавить эту кнопку в accessViewView
  4. Установить метод для кнопки

Я предоставляю вам некоторую помощь с кодом:

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

}

Надеюсь, это наверняка сработает для вас ....

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...