панорамирование ячеек с пользовательским действием в ios

Привет, я пытаюсь создать табличное представление с панорамированием в стиле почтового ящика http://www.mailboxapp.com/ для этого я использую эту библиотеку https://github.com/gloubibou/HHPanningTableViewCell, и она работает нормально, я проведите по ячейке, и она перемещается нормально, проблема в том, что я хочу вызвать пользовательское действие, когда я прокручиваю ячейку, и я смог сделать это только тогда, когда она открыта, а затем я прикасаюсь к ней.

Это код, в котором происходит действие

    #import "TableViewController.h"

#import "HHPanningTableViewCell.h"


@interface TableViewController ()

@property (nonatomic, retain) NSArray *rowTitles;

@end


@implementation TableViewController


#pragma mark -
#pragma mark Initialization

- (id)init
{

    self = [super initWithNibName:@"TableViewController" bundle:nil];

    if (self != nil) {
        self.rowTitles = [NSArray arrayWithObjects:@"Pan direction: None", @"Pan direction: Right", @"Pan direction: Left", @"Pan direction: Both", @"Custom trigger", nil];
    }

    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];



    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark -
#pragma mark Accessors

@synthesize rowTitles = _rowTitles;


#pragma mark -
#pragma mark Rotation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}


#pragma mark -
#pragma mark Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.rowTitles count] * 1;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSInteger directionMask = indexPath.row % 5;


    if (cell == nil) {
        cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                              reuseIdentifier:CellIdentifier];

        UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];

        // dark_dotted.png obtained from http://subtlepatterns.com/dark-dot/
        // Made by Tsvetelin Nikolov http://dribbble.com/bscsystem
        drawerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dark_dotted"]];

        cell.drawerView = drawerView;       
    }

    if (directionMask < 3) {
        cell.directionMask = directionMask;
    }
    else {
        cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;

        if (directionMask == 4) {
            cell.delegate = self;
        }
    }

    cell.textLabel.text = [self.rowTitles objectAtIndex:directionMask];




    return cell;
}

- (void)gestureRecognizerDidPan:(UIPanGestureRecognizer*)gestureRecognizer{

}

#pragma mark -
#pragma mark Table view delegate



- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
     NSInteger directionMask = indexPath.row;
    NSString *celda = [NSString stringWithFormat:@"%d", directionMask];

    [cell isKindOfClass:[HHPanningTableViewCell class]];
    HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;


    if (directionMask == 1) {
        if (HHPanningTableViewCellDirectionRight) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"1"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
        if ([panningTableViewCell isDrawerRevealed]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"1"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"2"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
    }


    return indexPath;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

#pragma mark -
#pragma mark HHPanningTableViewCellDelegate

- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                    message:@"You triggered a custom action"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

@end

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

в этой части я запускаю действие, точно зная ячейку, где она была панорамирована и открыта ли задняя часть ячейки или нет, но всегда щелкая по ней, поскольку это функция выбора.

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
     NSInteger directionMask = indexPath.row;
    NSString *celda = [NSString stringWithFormat:@"%d", directionMask];

    [cell isKindOfClass:[HHPanningTableViewCell class]];
    HHPanningTableViewCell *panningTableViewCell = (HHPanningTableViewCell*)cell;


    if (directionMask == 1) {
        if (HHPanningTableViewCellDirectionRight) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"1"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
        if ([panningTableViewCell isDrawerRevealed]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"1"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
        else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                            message:@"2"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
    }


    return indexPath;
} 

и я считаю, что в этой другой части должно запускаться пользовательское действие, но программа никогда не входит в эту функцию.

- (void)panningTableViewCellDidTrigger:(HHPanningTableViewCell *)cell inDirection:(HHPanningTableViewCellDirection)direction
{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Custom Action"
                                                    message:@"You triggered a custom action"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
    [alert show];
}

Надеюсь, я ясно выразился и заранее благодарю вас.


person Arturo    schedule 08.09.2013    source источник


Ответы (2)


Измените метод делегата на

- (void)panningTableViewCell:(HHPanningTableViewCell *)cell didTriggerWithDirection:(HHPanningTableViewCellDirection)direction;
person sutee    schedule 21.11.2013

Чтобы сработал метод делегата, вам нужно установить контроллер в качестве делегата для ячейки. В настоящее время в вашем cellForRowAtIndexPath контроллер назначается делегатом только тогда, когда directionMask равно 4. Таким образом, вы либо устанавливаете directionMask равным 4 в своем текущем коде (который вместо этого возвращает значение на основе позиции ячейки), либо вы устанавливаете контроллер в качестве делегата в каждом случай, как я сделал ниже.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    HHPanningTableViewCell *cell = (HHPanningTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSInteger directionMask = indexPath.row % 5;


    if (cell == nil) {
        cell = [[HHPanningTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                              reuseIdentifier:CellIdentifier];

        UIView *drawerView = [[UIView alloc] initWithFrame:cell.frame];

        // dark_dotted.png obtained from http://subtlepatterns.com/dark-dot/
        // Made by Tsvetelin Nikolov http://dribbble.com/bscsystem
        drawerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dark_dotted"]];

        cell.drawerView = drawerView;       
    }

    if (directionMask < 3) {
        cell.directionMask = directionMask;
    }
    else {
        cell.directionMask = HHPanningTableViewCellDirectionLeft + HHPanningTableViewCellDirectionRight;

        // previous code
        //if (directionMask == 4) {
        //    cell.delegate = self;
        //}
    }
    cell.delegate = self;

    cell.textLabel.text = [self.rowTitles objectAtIndex:directionMask];

    return cell;
}
person Morekid    schedule 23.01.2014