I don’t understand why the code isn’t working, and nothing I found seems to be working. So I’ve come here for help. Ultimately, I want to be able to send my link to Safari whenever I click on the “View” button, and I want the link to be copied whenever I click on the “Copy” button.
Here’s the code (under ” – (void)viewDidLoad “):
NSMutableArray *sites = [[NSMutableArray alloc] initWithObjects:@"http://www.apple.com/", @"http://www.youtube.com/", @"http://maps.google.com/", @"http://ww.google.com/", @"http://www.stackoverflow.com/", nil];
self.cloudsendList = sites;
Here is the code (under ” – (IBAction) touchUpInsideAction:(UIButton*)button “):
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
NSUInteger index = [buttons indexOfObject:button];
NSDictionary* buttonInfo = [buttonData objectAtIndex:index];
if ([[buttonInfo objectForKey:@"title"] isEqualToString:@"View"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", indexPath.row]]];
} else if ([[buttonInfo objectForKey:@"title"]isEqualToString:@"Copy"]) {
NSString *message = indexPath.row;
[UIPasteboard generalPasteboard].string = message;
Just to note, I am able to see the NSMutableArray data on each cell, I just can’t grab it. I’ve also tried to insert “cloudsendList indexPath.row” instead of just “indexPath.row”, but it didn’t work. I hope this gives you enough information, and any bit of help would be really appreciated. Also, I apologize if I sound kind of noobish; I’m still sort of new to Objective-C programming. Thanks! 🙂
indexPath.row is an NSInteger, not the text at that location. This means your NSString *message is getting the integer value of the row you are on (0, 1, 2…). Try using that location as an index when pulling from your sites/cloudsendList array.
Ex.
UPDATE:
To open the browser, use the same concept.