我不明白为什么代码不起作用,我发现的任何东西似乎都没有用。所以我来这里寻求帮助。最终,每当我点击“查看”按钮时,我希望能够将我的链接发送到Safari,并且我希望每当我点击“复制”按钮时都会复制链接。
这是代码(在“ - (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;
这是代码(在“ - (IBAction)touchUpInsideAction:(UIButton *)按钮”下):
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;
请注意,我能够在每个单元格上看到NSMutableArray数据,我无法抓住它。我也尝试插入“cloudsendList indexPath.row”而不仅仅是“indexPath.row”,但它没有用。我希望这能为您提供足够的信息,我们将非常感激您的帮助。另外,如果我听起来有点吵闹,我道歉;我仍然是Objective-C编程的新手。谢谢! :)
答案 0 :(得分:1)
indexPath.row是NSInteger,而不是该位置的文本。这意味着您的NSString *消息正在获取您所在行的整数值(0,1,2 ......)。从您的sites / cloudsendList数组中提取时,请尝试将该位置用作索引。
实施例。
NSString *message = [cloudsendList objectAtIndex:indexPath.row];
更新:
要打开浏览器,请使用相同的概念。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", [cloudsendList objectAtIndex:indexPath.row]]]];