Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override method syntax ios

I'm trying to override a method in my cellForRowAtIndexPath method like this

cell.customSwitch {
    - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
    {
        [super touchesEnded:touches withEvent:event];
        NSLog(@"customSwitch touchesended");
    }

};

however this isn't working (I'm normally a Java guy :P). Any help would be much appreciated!

like image 219
mikez Avatar asked Aug 24 '26 02:08

mikez


1 Answers

There are a lot of similarities between Objective-C and Java, but that's not one of 'em. ;-)

If you want to create a cell with a customized -touchesEnded:withEvent: method, you'll need to declare and define that class separately. Something like:

@interface MyCell : UITableViewCell
{
//...
}
@end

@implementation MyCell
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    [super touchesEnded:touches withEvent:event];
    NSLog(@"customSwitch touchesended");
}
@end

Once you've done that, you can use MyCell in your -cellForRowAtIndexPath:.

like image 137
Caleb Avatar answered Aug 25 '26 17:08

Caleb



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!