複数の NSString を 1 つにまとめた単純なプロジェクトがあります。次に、その文字列がクリップボードにコピーされます。コードは次のとおりです。
#import "CopyToClipViewController.h"
@interface CopyToClipViewController ()
@end
@implementation CopyToClipViewController
@synthesize device;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
if (self.device) {
NSString *namevalue;
NSString *versionvalue;
NSString *companyvalue;
namevalue = [self.device valueForKey:@"name"];
versionvalue = [self.device valueForKey:@"version"];
companyvalue = [self.device valueForKey:@"company"];
NSString *shareString = [NSString stringWithFormat:@"I have performed %@ minutes of %@ %@",namevalue, versionvalue, companyvalue];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = shareString;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
ただし、シミュレーターでプロジェクトをビルドして実行した後、文字列を他のアプリに貼り付けられないようです。どうした?前もって感謝します!