2

这是在最新的 Xcode 中。

我有 4 个数组,它们通过 OK 按钮在屏幕上生成结果。我想添加一个将结果复制到剪贴板的函数。那有意义吗?

虽然我不确定这是如何完成的,但我正在大量研究它,因为我对编码有点陌生。

从我所见,粘贴板似乎是要走的路。我在正确的球场吗?

这是我的代码示例...

-(IBAction)buttonPressed
{
NSInteger firstRow = [doublePicker selectedRowInComponent:kfirstComponent];
NSInteger middleRow = [doublePicker selectedRowInComponent:kmiddleComponent];
NSInteger lastRow = [doublePicker selectedRowInComponent:klastComponent];
NSInteger fourthRow = [doublePicker selectedRowInComponent:kfourthComponent];
NSString *first = [firstTypes objectAtIndex:firstRow];
NSString *middle = [middleTypes objectAtIndex:middleRow];
NSString *last = [lastTypes objectAtIndex:lastRow];
NSString *fourth = [fourthTypes objectAtIndex:fourthRow];
NSString *message = [[NSString alloc] initWithFormat:@"%@ %@ %@ %@.",first, middle, last, fourth]; 
UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Text"
    message:message
            delegate:nil
    cancelButtonTitle:@"OK"
    otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
}

这是我想要实现的代码(我认为):

-(IBAction)copy:(id)sender
{
NSString *copyString = label.text;
UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:copyString];
}

而且......如果我有正确的用法,我不知道把它放在哪里......

先感谢您!!!

编辑-

我想通了...我只需要添加:

UIPasteboard *pb = [UIPasteboard generalPasteboard];
[pb setString:message];

在提供我的结果的代码行下方。我知道这听起来很弱,但是......我认为能够自己解决一次真是太棒了!

4

0 回答 0