Reputation: 21
I am not able to use one of my methods that i implemented in my tableviewcell file in my tableview controller implementation. I tried searching the web and xcode help with no luck. My codes looks like this:
TableViewController.h:
#import TableViewCell.h
@interface TableViewController : UITableViewController
@property (nonatomic, strong) IBOutlet UIBarButtonItem *A1Buy;
@property (nonatomic, getter = isUserInteractionEnabled) BOOL userInteractionEnabled;
- (IBAction)A1Buy:(UIBarButtonItem *)sender;
TableViewController.m:
@implementation A1ViewController
@synthesize A1Buy = _A1Buy;
@synthesize userInteractionEnabled;
- (IBAction)A1Buy:(UIBarButtonItem *)sender {
[TableViewCell Enable]; //this is where it gives an error
}
TableViewCell.h:
@interface TableViewCell : UITableViewCell {
BOOL Enable;
BOOL Disable;
}
@property (nonatomic, getter = isUserInteractionEnabled) BOOL userInteractionEnabled;
TableViewCell.m:
@implementation TableViewCell;
@synthesize userInteractionEnabled;
- (BOOL) Enable {
return userInteractionEnabled = YES;
}
- (BOOL) Disable {
return userInteractionEnabled = NO;
}
As you can see i am trying to enable user interaction with a button, but Xcode only gives me errors like "class does not have this method" and stuff like that. All files are importet correctly so thats not why. Would appreciate any help. Thanks!
Upvotes: 2
Views: 105
Reputation: 107231
You are declared the - (BOOL) Enable
as an instance method. You cannot call the instance method using Class name.
Solutions:
Declare the method as Class method
+ (BOOL) Enable
Create an object of the class then call the method using that object
TableViewCell *cellObj = [[TableViewCell alloc] init];
[cellObj Enable];
Please read more about class method here.
Please refer the ios coding conventions here.
Upvotes: 0
Reputation: 119292
First, name your methods and variables according to Cocoa standards - classes have a capitalised first letter, variables and methods have a lower case first letter.
Doing that should make it obvious that you're calling the Enable
method on the TableViewCell
class, where it is actually an instance method. You need to get a pointer to a specific table view cell and call the method on that.
Also, your methods as implemented are very confusing. Why are they returning the result of an assignment as a Boolean? This will always return YES. You may need to study some basic objective-c training resources.
Upvotes: 1