我知道如何将一个类的方法调用到另一个类。然而,这一次它对我不起作用,它只是让我发疯。下面是我的代码
菜单页单元格.h
#import <UIKit/UIKit.h>
@class MenuPageViewController;
@interface MenuPageCell : UITableViewCell{
NSInteger m_cellIndex;
MenuPageViewController *m_parentViewController;
}
@property(nonatomic, assign) NSInteger m_cellIndex;
@property(nonatomic, strong) MenuPageViewController *m_parentViewController;
-(IBAction) addToCart;
@end
菜单页单元格.m
#import "MenuPageCell.h"
#import "MenuPageViewController.h"
@implementation MenuPageCell
@synthesize m_cellIndex;
@synthesize m_parentViewController;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
-(IBAction) addToCart
{
NSLog(@"Add To cart = %d",self.m_cellIndex);
[m_parentViewController addItemToCart:self.m_cellIndex];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
MenuPageViewController.m
-(void) addItemToCart:(NSInteger)aIndexItem
{
NSLog(@"In Add to Cart method");
}
现在,此代码适用于非 ARC 使用的项目,但它不适用于我。我知道这应该是愚蠢的错误,但我无法弄清楚。
感谢和问候
马尤尔