Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclassing MGSwipeTableCell #5

Closed
plaetzchen opened this issue Sep 1, 2014 · 19 comments
Closed

Subclassing MGSwipeTableCell #5

plaetzchen opened this issue Sep 1, 2014 · 19 comments

Comments

@plaetzchen
Copy link

Hi,

I am trying to use MGSwipeCell in a storyboard based app. I subclassed my table cell views for using custom IBOutlets. Now I changed the Superclass of those classes to "MGSwipeTableCell" and added two left buttons to the cell but I simple can't get the buttons to show up. Do I need to change something in my sub-classes?

Thank you for your work!

Philip

@MortimerGoro
Copy link
Owner

Hi Philip,

Changing the superclass to MGSwipeTableCell and adding the left buttons should be enough.

I have a test using storyboards in the demo project but I can't reproduce the issue. Please, send me a testcase that reproduces the problem and I will debug it ;)

@brightsider
Copy link

+1
I'm create custom cell with subclass and this don't work (@interface CheckInCell : MGSwipeTableCell).
Work only with original cell.

@brightsider
Copy link

I'm fixing it - in subclassed cell added this:

  • (void)awakeFromNib
    {
    [super awakeFromNib];
    }

@MortimerGoro
Copy link
Owner

Yeah, you should always call super methods because MGSwipeTableCell or the original UITableViewCell might have some work to do ;)

Philip, does the super method call fix your problem?

@hemangshah
Copy link

Subclass MGSwipeTableCell instead of UITableViewCell
I've resolved the issue by implementing

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {
        //add your cell objects here
    }
    return self;
}

I commented,
//- (void)awakeFromNib {
// [super awakeFromNib];
//}

It works fine now,

In table view datasource implementation, its same like we are doing.

  static NSString *cellIdentifier = @"cellIdentifier";
  Custom *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  if(cell == nil) {
      cell = [[Custom alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  }

@mbellmbell
Copy link

Also having difficulty with subclassing MGSwipeCell. I don't get any swipe behavior when first displaying cells, but if I scroll cells out of view and then back into view the swipe behavior works for those cells.

The MGSwipeCell subclass loads its view from a nib.

@ellern
Copy link

ellern commented Sep 14, 2014

Me too, can't get it to work. I'm loading my tableview from a nib file.

In my viewDidLoad:
[self.tableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:@"CustomReuseIdentifier"];

Then in tableView cellForRowAtIndexPath:
MGSwipeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomReuseIdentifier" forIndexPath:indexPath];

The cells render fine, but I'm not able to swipe.

@waltermvp
Copy link

I had the same issue. And also registered cells like so:

    [self.tableView registerNib:[UINib nibWithNibName:userCellIdentifier bundle:nil]
         forCellReuseIdentifier:userCellIdentifier];

Calling

    [super awakeFromNib];

fixed the issue

@ellern
Copy link

ellern commented Sep 17, 2014

Not working for me, any chance you can share your code?

@mbellmbell
Copy link

Yup.
-(void)awakeFromNib { [super awakeFromNib]; } in the MGSwipeTableCell subclass works for me.

@MortimerGoro
Copy link
Owner

Fixed. I have implemented - (id)initWithCoder:(NSCoder*)aDecoder to avoid relying only on awakeFromNib to do some internal initializations. Now it works even if you don't call [super awakeFromNib].

@scorpionking2k5
Copy link

Using a subclass with a nib.
Tried using with and without delegate.
Delegate methods get called but nothing happening still. Failing to get any swipe action at all.

Tried all the solutions mentioned above. Nothing still working.

iOS 8 + iPad 2 simulator + XCode 6.1.1

@jaisongreen
Copy link

I am having the same issue as scorpionking2k5.

Subclassing with a XIB, delegate methods get called but swipe buttons dont show up at all.

@Errortype520
Copy link

Still an issue using Swift 2, and Xcode 7. Cells do not swipe. Loading cell from XIB.

@ghost
Copy link

ghost commented Feb 11, 2017

I have exactly the same problem. Swipe fails to work when loading the cell from xib; otherwise it works fine.

@siralam
Copy link

siralam commented Jan 25, 2018

Reporting same problem as above.

The way I do this is:

In ViewController:

        tableView.register(CustomTableCell.self, forCellReuseIdentifier: "Cell")
        tableView.dataSource = self
        tableView.delegate = self

CustomTableCell.swift:

class CustomTableCell: MGSwipeTableCell {
    
    @IBOutlet var rootView: UIView!
    @IBOutlet weak var itemName: UILabel!
    @IBOutlet weak var itemRating: UILabel!
    @IBOutlet weak var itemSwitch: UISwitch!
    
    required override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        commonInit()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }
    
    private func commonInit () {
        Bundle.main.loadNibNamed("CustomTableCell", owner: self, options: nil)
        addSubview(rootView)
        rootView.frame = self.bounds
        rootView.autoresizingMask = [.flexibleHeight, .flexibleWidth]
    }
    
}

@bineshpavithran
Copy link

same issue here, swiping is not working when cell is loaded from a xib file. Any solution?

@richardlevy
Copy link

This is happening for me. I just migrated a cell from storyboard to a XIB to make it reusable and swipes don't work. I can see that it receives pan gestures OK and is setting offsets but nothing appears on the screen. I've got super calls to awakeFromNib, and initWithDecoder but nothing ever gets displayed.

I've even tried calling the interval initViews later in the lifecycle to see if that helps and it doesn't.

I've updated to the latest source too.

Still, nothing.

Did anyone crack this?

@richardlevy
Copy link

I cracked this!

It was my fault of course. In the XIB, which I had created separately from the class, I had created my layout inside the default view (which was a UIView). I should have dragged a UITableViewCell in and created my view with that.

Once I did that it worked fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests