Im building an iphone app through xcode and objective c. building for ios5.0 min target.
I created a custom uitablecell and im loading this within a table in a view controller no problems. this cell contains a button. when the user taps this button within any of the cells i want it to call the same function within the view controller. The way i have done this in the past is by making the file owner of the custom cell the viewcontroller in question and then simply control drag the button into the view controller and place the ibaction function there. always works no problem. until now.
-[__NSCFString loadMerchant:]: unrecognized selector sent to instance 0x8689e50 2012-05-24 09:56:14.630 [3217:16103] * Terminating
app due to uncaught exception ‘NSInvalidArgumentException’, reason:
‘-[__NSCFString loadMerchant:]: unrecognized selector sent to instance
0x8689e50’
this is the error im getting. I am making sure that the function is not accidently linked to the wrong button, that the function isnt also in the cell.m by mistake and any other simple mistakes i can think of.
Does anyone know the correct way to accomplish what im trying to do?
edit: custom cell
@interface TimelineCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UIButton *nameButton;
@end
@implementation TimelineCell
@synthesize nameButton;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self; }
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state }
@end
below is the viewcontroller
- (IBAction)loadMerchant:(id)sender;
- (IBAction)loadMerchant:(id)sender { }
and thats it. crash happens when ever the button is tapped with above error
edit: dropping the link within the nib file and just maually add the action to the button seems to solve the issue but id still liek to know the cause of it if anyone can shed some light on that would be appreciated
made within cellForRowAtIndexPath
UIButton *b = (UIButton*)[cell viewWithTag:1];
[b addTarget:self action:@selector(loadMerchant:) forControlEvents:UIControlEventTouchUpInside];
what i ended up doing was tagging the button within the nib file and then in code adding the target through code in the cell set up in cellForRowAtIndexPath.
while this solves the problem I am still unsure as to why the link made through IB failed in the first place.