alfiehanssen / ios-viewcontroller-containment

A simple UIViewController containment example
MIT License
2 stars 0 forks source link

Problems using UIPanGestureRecognizer in UITableViewCell #5

Open jasanchezsa opened 10 years ago

jasanchezsa commented 10 years ago

First congratulations for the project.

I'm trying to add a table in a UIViewController but the swipe gesture is not working properly. I tried with the following delegates GestureRecognizerDelegates:

I have also tried the fault property: requireGestureRecognizerToFail

Any idea?

Thank you very much.

alfiehanssen commented 10 years ago

Can you please post more of your code? Specifically the class with that tableview or the portion of your class that creates and adds the tableview.

On Tue, Jan 21, 2014 at 8:12 PM, elpatxificador notifications@github.com wrote:

First congratulations for the project. I'm trying to add a table in a UIViewController but the swipe gesture is not working properly. I tried with the following delegates GestureRecognizerDelegates:

  • (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
  • (BOOL)gestureRecognizer:(UIGestureRecognizer )gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer )otherGestureRecognizer I have also tried the fault property: requireGestureRecognizerToFail Any idea? Thank you very much.

    Reply to this email directly or view it on GitHub: https://github.com/alfiehanssen/ios-viewcontroller-containment/issues/5

jasanchezsa commented 10 years ago

For example I added UITableView. The problem is that the method is called before didSelectRowAtIndexPath that uipangesturerecognizer and not moving to another controller.

My code:

#import <UIKit/UIKit.h>
#import "ContentViewController.h"
#import "SeccionTableCell.h"

@interface PortadaViewController : ContentViewController <UITableViewDataSource, UITableViewDelegate, SeccionTableCellDelegate>

@property (nonatomic, weak) IBOutlet UITableView *myTableView;
@property (nonatomic, strong) NSMutableArray *arrayContentData;

//-----------------------------------------------------------------------------------------------------------

#import "PortadaViewController.h"

@interface PortadaViewController ()

@end

@implementation PortadaViewController

@synthesize arrayContentData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

#pragma mark -
#pragma mark - viewDidLoad
#pragma mark -

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self.view setBackgroundColor:[UIColor clearColor]];

    [self.myTableView setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+self.heightHeader, self.view.frame.size.width, self.view.frame.size.height-self.heightHeader)];

    arrayContentData = [[NSMutableArray alloc] initWithObjects:@"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", nil];
}

#pragma mark -
#pragma mark - UITableView DataSource
#pragma mark -

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayContentData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";
    SeccionTableCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SeccionTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

        [cell setDelegate:self];
        [cell drawElementsScroll];
    }

    cell.imageViewFoto.image = [UIImage imageNamed:@"sample.png"];
    cell.labelTitulo.text = [arrayContentData objectAtIndex:indexPath.row];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return TABLE_SECCION_CELL_HEIGHT;
}

#pragma mark -
#pragma mark - UITableView Delegates
#pragma mark -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    NSLog(@"PUSH CELL");
}

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

My TableCell:

captura de pantalla 2014-01-28 a la s 21 10 58

Thank you very much!

alfiehanssen commented 10 years ago

It's tough to say what the issue is without inspecting the code further. I have used a modified version of this project to manage a set of ViewControllers each containing a UITableView so it's definitely possible. I think you're on the right track with making sure the gestures play nice with one another. Within those delegate methods you would check to see which gestures you are being asked about. Or you could do that in the ContainerViewController. Good luck!

On Tue, Jan 28, 2014 at 3:16 PM, elpatxificador notifications@github.comwrote:

For example I added UITableView. The problem is that the method is called before didSelectRowAtIndexPath that uipangesturerecognizer and not moving to another controller.

My code:

import <UIKit/UIKit.h>

import "ContentViewController.h"

import "SeccionTableCell.h"

@interface PortadaViewController : ContentViewController <UITableViewDataSource, UITableViewDelegate, SeccionTableCellDelegate>

@property (nonatomic, weak) IBOutlet UITableView myTableView; @property (nonatomic, strong) NSMutableArray arrayContentData;

//-----------------------------------------------------------------------------------------------------------

import "PortadaViewController.h"

@interface PortadaViewController ()

@end

@implementation PortadaViewController

@synthesize arrayContentData;

  • (id)initWithNibName:(NSString )nibNameOrNil bundle:(NSBundle )nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; }

pragma mark -

pragma mark - viewDidLoad

pragma mark -

  • (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib.

    [self.view setBackgroundColor:[UIColor clearColor]];

    [self.myTableView setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+self.heightHeader, self.view.frame.size.width, self.view.frame.size.height-self.heightHeader)];

    arrayContentData = [[NSMutableArray alloc] initWithObjects:@"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", @"1", nil]; }

pragma mark -

pragma mark - UITableView DataSource

pragma mark -

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [arrayContentData count]; }
  • (UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath )indexPath { static NSString simpleTableIdentifier = @"SimpleTableCell"; SeccionTableCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SeccionTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0];

    [cell setDelegate:self];
    [cell drawElementsScroll];

    }

    cell.imageViewFoto.image = [UIImage imageNamed:@"sample.png"]; cell.labelTitulo.text = [arrayContentData objectAtIndex:indexPath.row];

    return cell; }

  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath { return TABLE_SECCION_CELL_HEIGHT; }

pragma mark -

pragma mark - UITableView Delegates

pragma mark -

  • (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; NSLog(@"PUSH CELL"); }
  • (void)tableView:(UITableView )tableView didDeselectRowAtIndexPath:(NSIndexPath )indexPath { }

My TableCell:

[image: captura de pantalla 2014-01-28 a la s 21 10 58]https://f.cloud.github.com/assets/2070957/2023186/67d70d84-8858-11e3-8bad-014b9d44b257.png

Thank you very much!

Reply to this email directly or view it on GitHubhttps://github.com/alfiehanssen/ios-viewcontroller-containment/issues/5#issuecomment-33519998 .

alfiehanssen commented 10 years ago

@elpatxificador,

I pushed some changes today and updated the README, take a look at the updated code and let me know if you're still having a problem. Best of luck.