开发者

Override method syntax ios

开发者 https://www.devze.com 2023-03-19 17:37 出处:网络
I\'m trying to override a method in my cellForRowAtIndexPath method like this cell.customSwitch { - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event

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 thi开发者_开发百科s isn't working (I'm normally a Java guy :P). Any help would be much appreciated!


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:.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号