Steaphann Steaphann -4 years ago 39
iOS Question

Working with a button in a custom tableview Cell

I have a facebook like button in a custom tableview cell. In the class of my tableview I have the following function.

- (IBAction)sendLike:(id)sender
WithString: (NSString *)shareString
andUrl:(NSURL *)shareUrl{

//Do all kinds of things


[fbController setInitialText:shareString];
[fbController addURL:shareUrl];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
}


In my cellForRowAtIndexpath I am trying to call this method in the following way.

NSString *shareString = video.name;
NSURL *shareUrl = [NSURL URLWithString:video.url];
[cell.facebook addTarget:self action:@selector(sendLike: WithString:shareString andUrl:shareUrl)
forControlEvents:UIControlEventTouchUpInside];


But it is complaining that I should put ':' in my @selector. Can anybody help ?

Thanks in advance.

Answer Source

You can try like this

cell.facebook.tag = indexPath.row.
    [cell.facebook addTarget:self action:@selector(sendLike:)
                     forControlEvents:UIControlEventTouchUpInside];

in sendLike event

- (IBAction)sendLike:(id)sender
  {


        //if you want to fetch data from any list then try
        //UIButton *selectedButton = (UIButton*)sender;
        //data = [dataList objectAtIndex:selectedButton.tag];
        NSString *shareString = video.name;
        NSURL *shareUrl = [NSURL URLWithString:video.url];

        [fbController setInitialText:shareString];
        [fbController addURL:shareUrl];
        [fbController setCompletionHandler:completionHandler];
        [self presentViewController:fbController animated:YES completion:nil];
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download