gpt4 book ai didi

cocoa - 将字符串写入 NSPasteBoard

转载 作者:行者123 更新时间:2023-12-03 16:01:25 25 4
gpt4 key购买 nike

我无法让此方法返回 YES:

- (BOOL) writeToPasteBoard:(NSString *)stringToWrite
{
return [pasteBoard setString:stringToWrite forType:NSStringPboardType];
}

我已经验证 stringToWrite 是否正确通过,该方法总是返回 NO。

有什么想法吗?

这是类(class)的其余部分:

@interface ClipBoard : NSObject {
NSPasteboard *pasteBoard;
}

- (BOOL) writeToPasteBoard:(NSString *)stringToWrite;
- (NSString *) readFromPasteBoard;
@end

@implementation ClipBoard
- (id) init
{
[super init];
pasteBoard = [NSPasteboard generalPasteboard];
return self;
}

- (BOOL) writeToPasteBoard:(NSString *)stringToWrite
{
return [pasteBoard setString:stringToWrite forType:NSStringPboardType];
}

- (NSString *) readFromPasteBoard
{
return [pasteBoard stringForType:NSStringPboardType];
}

@结束

最佳答案

这是该方法的工作版本:

- (BOOL) writeToPasteBoard:(NSString *)stringToWrite
{
[pasteBoard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
return [pasteBoard setString:stringToWrite forType:NSStringPboardType];
}

关于cocoa - 将字符串写入 NSPasteBoard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/598587/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com