我正在尝试创建一个允许您以不同方式使用数据的应用程序。具体来说,您可以使用if语句查看,复制,编辑和删除我尝试执行此操作的信息。问题是,当我构建并运行时,按钮不会执行我希望他们执行的操作。特别是,我希望“查看”按钮将链接发送到Safari,并使用“复制”按钮将数据复制到剪贴板。 “编辑”按钮和“删除”按钮不需要立即激活。
这是按钮的代码(在“ - (void)viewDidLoad”下面):
buttonData = [[NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"View", @"title", @"view.png", @"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Copy", @"title", @"copy.png", @"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Edit", @"title", @"edit.png", @"image", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Delete", @"title", @"delete.png", @"image", nil],
nil] retain];
buttons = [[NSMutableArray alloc] initWithCapacity:buttonData.count];
以下是if语句的代码(在“ - (IBAction)touchUpInsideAction:(UIButton *)按钮”下):
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
NSUInteger index = [buttons indexOfObject:button];
NSDictionary* buttonInfo = [buttonData objectAtIndex:index];
if ([buttonInfo objectForKey:@"View"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: @"%@", indexPath.row]]];
} else if ([buttonInfo objectForKey:@"Copy"]) {
NSString *message = indexPath.row;
[UIPasteboard generalPasteboard].string = message;
}
如果您需要查看更多代码,请告诉我;我只是认为这些是您需要查看的唯一代码行。
我似乎无法找到解决方案,这让我发疯。谁能帮助我?我希望这不会造成太大麻烦。提前致谢! :)