我遇到了一个问题,即离开时,键盘不会被解雇UITextField或UITextView在UIModalPresentationFormSheet.另外,我创建了一个大按钮作为视图的背景,因此如果用户点击字段之外它会被触发.我在常规视图控制器中使用相同的代码,它按预期工作.在模态视图控制器中它什么都不做.任何建议,将不胜感激.
- (BOOL)textFieldShouldReturn:(id)sender {
[titleTextField resignFirstResponder];
return YES;
}
- (BOOL)textViewShouldReturn:(id)sender {
[synopsisTextView resignFirstResponder];
return YES;
}
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)textViewDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroundClick:(id)sender {
[titleTextField resignFirstResponder];
[synopsisTextView resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud) 如何在Mac应用程序中添加"共享"子菜单?一个例子是Safari>文件>共享.我戳了Apple SharingServices示例代码,但它没有包含工作菜单项.

现在我有一个按钮,在点击时显示可用共享服务的选择器:
NSMutableArray *shareItems = [NSMutableArray arrayWithObject:[self.noteSynopsisView string]];
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:shareItems];
sharingServicePicker.delegate = self;
[sharingServicePicker showRelativeToRect:[self.shareButton bounds] ofView:self.shareButton preferredEdge:NSMaxYEdge];
Run Code Online (Sandbox Code Playgroud)
我还在MainWindow.xib的File菜单下定义了一个Share子菜单项.
据我了解,NSSharingService列表正在动态生成.所以我不能真正预定义我在Interface Builder中创建的菜单项的服务.
谢谢你的帮助.
我UIWebview使用loadHtmlString加载本地html文件.加载的页面包含指向其他本地html文件的链接以及使用互联网的真实链接.
我添加了一个后退按钮:
if([self.webView canGoBack])[self.webView goBack];
这工作正常,除了它不能识别加载loadHtmlString的原始页面.
例如,如果我导航:
local - > local - > web
local X local < - web(第一个返回工作,下一个什么都不做.)
如何让webview识别原始页面,以便后退按钮也适用于它?我能以某种方式将它添加到webview的历史中吗?
提前致谢!
我有一个应用程序,旨在通过Localizable.strings文件本地化为5种语言.当我查看项目>信息:本地化信息时,我看到一些语言(英语,法语,德语)和非预期语言(日语)的重复.

XCode中的我的资源也出现了.但是如果我查看Finder中的Resources目录,它们就像我期望的那样出现.

我试过了:
我很感激任何建议和解释.我在小牛队上使用XCode 6.1.1.谢谢.
如何为使用NSSharingService组成的邮件消息定义主题?
我已经浏览了NSSharingService类引用,但我没有看到它在任何地方定义.以下成功启动邮件应用程序,但主题只是与文本一起塞进邮件正文.
NSAttributedString *text = [self.noteSynopsisView attributedString];
NSString *subject = @"My Subject";
NSArray *shareItems = [NSArray arrayWithObjects:text, subject, nil];
NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:shareItems];
sharingServicePicker.delegate = self;
[sharingServicePicker showRelativeToRect:[self.shareButton bounds] ofView:self.shareButton preferredEdge:NSMaxYEdge];
Run Code Online (Sandbox Code Playgroud)
在iOS中,您通常会执行以下操作来定义MailComposer的主题
[sharingServicePicker setSubject:@"My Subject"];
Run Code Online (Sandbox Code Playgroud)
但SharingServicePicker不支持setSubject.
比较或测试NSAttributed字符串的特定颜色属性的正确方法是什么?
作为一个例子,我想知道文本选择是否有红色文本.我已经尝试了几种方法,如下所示,但它们都没有产生匹配.我看到文本在屏幕上变为红色,并且记录该属性返回:UIDeviceRGBColorSpace 1 0 0 1
- (BOOL)isRedWithAttributes:(NSDictionary *)attributes
{
BOOL isRedWithAttributes = NO;
if (attributes != nil)
{
// if ( [attributes objectForKey:NSForegroundColorAttributeName] == [UIColor redColor] )
// if ( [attributes objectForKey:NSForegroundColorAttributeName] == @"UIDeviceRGBColorSpace 1 0 0 1" )
if ( [attributes objectForKey:NSForegroundColorAttributeName] == [UIColor colorWithRed:1 green:0 blue:0 alpha:1] )
{
isRedWithAttributes = YES;
}
else
{
isRedWithAttributes = NO;
}
}
return isRedWithAttributes;
}
Run Code Online (Sandbox Code Playgroud)
以下是我为测试传递属性的方法:
NSAttributedString *selectedString = [attributedString attributedSubstringFromRange:selectedRange];
[selectedString enumerateAttributesInRange:NSMakeRange(0, [selectedString length])
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(NSDictionary *attributes, NSRange …Run Code Online (Sandbox Code Playgroud) 我试图让用户能够设置他们将键入下划线的文本,而不会选择当前的文本.这适用于iOS 6应用程序,在UITextView中输入文本.它将保存为NSAttributedString.大胆和斜体很好.关于下划线的一些事情是让它无法工作.
UITextView *textView = [self noteTextView];
NSMutableDictionary *typingAttributes = [[textView typingAttributes] mutableCopy];
[typingAttributes setObject:[NSNumber numberWithInt:NSUnderlineStyleSingle] forKey:NSUnderlineStyleAttributeName];
NSLog(@"attributes after: %@", typingAttributes);
[textView setTypingAttributes:typingAttributes];
NSLog(@"text view attributes after: %@", [textView typingAttributes]);
Run Code Online (Sandbox Code Playgroud)
我的初始日志语句表明它设置为下划线:
attributes after: {
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICFFont: 0xa9c5e30> font-family: \"Verdana\"; font-weight: normal; font-style: normal; font-size: 17px";
NSKern = 0;
NSStrokeColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSStrokeWidth = 0;
NSUnderline = 1;
}
Run Code Online (Sandbox Code Playgroud)
但紧接着的日志语句不显示nsunderline属性.删除textView setTypingAttributes行没有任何影响.
text view attributes after: {
NSColor = "UIDeviceRGBColorSpace …Run Code Online (Sandbox Code Playgroud) 我正在开发一个基本的击键转换器应用程序。该转换适用于以下情况:
CFRunLoopSourceRef runLoopSource = NULL;
CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);
runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
CGEventTapEnable(eventTap, true);
Run Code Online (Sandbox Code Playgroud)
正如您所料,kCGEventMaskForAllEvents除了键盘之外,任何鼠标移动或单击都会不断触发,我怀疑会占用系统资源。我尝试替换,我可以从Quartz Event 文档中关于事件类型CGEventMaskBit(kCGEventKeyDown)的最佳信息看出这是我想要的,并且会消除鼠标移动和点击。不幸的是,使用它似乎只是吃掉了击键,而不是转换它们。
我究竟做错了什么?
以下内容有效,但我仍然不明白为什么CGEventMaskBit(kCGEventKeyUp)它本身不是正确的实现。
CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(NX_SYSDEFINED)
Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟iOS Pages和Keynote应用程序的粘贴板行为。简而言之,允许将基本NSAttributedString文本格式(即BIU)粘贴到UITextView中,但不能粘贴到图像,HTML等中。
行为摘要
这是如何完成的?在Mac OS上,您似乎可以要求粘贴板返回不同类型的自身,让其提供富文本格式和字符串表示形式,并首选使用富文本格式。不幸的是,iOS似乎不存在readObjectsForClasses。就是说,由于这篇文章,我可以通过日志看到iOS确实具有与RTF相关的粘贴板类型。但是,我找不到一种方法来请求粘贴板内容的NSAttributedString版本,以便可以优先进行粘贴。
背景
我有一个应用程序,允许UITextViews中的文本的基本NSAttributedString用户可编辑格式(即,粗体,斜体,下划线)。用户想要从其他应用程序复制文本(例如Safari中的网页,Notes应用程序中的文本),以粘贴到我的应用程序中的UITextView中。允许剪贴板默认运行,意味着我可能会得到应用程序不打算处理的背景颜色,图像,字体等。下面的示例显示了文本,当粘贴到我的应用程序的UITextView中时,具有背景色的复制文本看起来如何。

我可以通过继承UITextView来克服1
- (void)paste:(id)sender
{
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSString *string = pasteBoard.string;
NSLog(@"Pasteboard string: %@", string);
[self insertText:string];
}
Run Code Online (Sandbox Code Playgroud)
意外的结果是,失去了保留从我的应用程序中复制的文本格式的功能。用户可能想要从我的应用程序中的一个UITextView复制文本,然后将其粘贴到我的应用程序中的另一个UITextView。他们希望保留格式(即粗体,斜体,下划线)。
的见解和建议表示赞赏。
有没有办法从行中单独禁用辅助指示器?我有一张桌子使用
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryDetailDisclosureButton;
}
Run Code Online (Sandbox Code Playgroud)
我需要为单行禁用它(删除图标而不触发详细信息泄露事件).我以为这会做到,但没有结果.该指示器仍然出现,它仍然接收和触摸事件.
cell.accessoryType = UITableViewCellAccessoryNone;
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何建议.
ios ×6
cocoa ×3
macos ×3
ios6 ×2
ipad ×2
iphone ×2
back ×1
cgeventtap ×1
compare ×1
copy-paste ×1
email ×1
ios7 ×1
keyboard ×1
localization ×1
menu ×1
menuitem ×1
sharing ×1
submenu ×1
uicolor ×1
uipasteboard ×1
uitableview ×1
uiwebview ×1
underline ×1
xcode ×1