0
votes

I have this method:

- (void)retweet:(NSString *)idString {
    STTwitterAPI *twitter;
    [twitter postStatusRetweetWithID:idString successBlock:^(NSDictionary *status) {
        UIAlertView *retweetSuccess = [[UIAlertView alloc]initWithTitle:@"Retweeted!" message:@"You have retweeted this tweet." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [retweetSuccess show];

    } errorBlock:^(NSError *error){

    }];
}

I also have a uibutton in my tableview cell so I was using [cell.retweetButton addTarget:self action:@selector(retweet:)forControlEvents:UIControlEventTouchUpInside];

How can I use my idString as the argument for the method parameter with the selector?

2
The selector called by an UIButton is a sort of -(void)selector: (UIButton *)buttonReference. You cannot retrieve a NSString from it.Luca D'Alberti

2 Answers

0
votes

If the id string is originating from button the change your action method parameter to paramButton and acces it. if it is from elsewhere then you need to simply get it from wherever it is comming from.

In any case, your action method has to have the :(UIButon *)paramButton parameter. ( (id)sender woul be also acceptable as an alternative).

0
votes

Use objective c associated objects

#import <objc/runtime.h>

static const void *idStringKey = &idStringKey;

@implementation UIButton (idString)

- (void)setIDString:(NSString *)idString
{
   objc_setAssociatedObject(self, idStringKey, idString, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSString *)idString
{
   return objc_getAssociatedObject(self, idStringKey);
}

@end

Use

cell.retweetButton.idString = @"Any string here"