有几个不同的方法来去除HTML tags
从NSString
在Cocoa
.
一种方法是将字符串渲染为a NSAttributedString
然后抓取渲染的文本.
另一种方法是使用NSXMLDocument's
- objectByApplyingXSLTString
方法来应用XSLT
执行它的变换.
不幸的是,iPhone不支持NSAttributedString
或NSXMLDocument
.有太多的边缘情况和格式错误的HTML
文档让我觉得使用正则表达式或NSScanner
.有人有解决方案吗?
一个建议是简单地查找开始和结束标记字符,除非非常简单的情况,否则此方法不起作用.
例如,这些案例(来自同一主题的Perl Cookbook章节)会打破这种方法:
<IMG SRC = "foo.gif" ALT = "A > B">
<!-- <A comment> -->
<script>if (a<b && a>c)</script>
<![INCLUDE CDATA [ >>>>>>>>>>>> ]]>
Run Code Online (Sandbox Code Playgroud) 多年前,当我使用C#时,我可以轻松地创建一个临时文件并使用此函数获取其名称:
Path.GetTempFileName();
Run Code Online (Sandbox Code Playgroud)
此函数将在临时目录中创建具有唯一名称的文件,并返回该文件的完整路径.
在Cocoa API中,我能找到的最接近的是:
NSTemporaryDirectory
Run Code Online (Sandbox Code Playgroud)
我错过了一些明显的东西,还是没有内置的方法来做到这一点?
当您添加多个自定义菜单项时,显然有一种简单的方法可以防止"更多..."标签出现在UIMenuController中.您只需删除所有系统菜单项.这里甚至有一个解决方法,仍然有复制工作.您只需使用不同的选择器实现自定义复制命令,然后覆盖canPerformAction:withSender:不显示系统副本:
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
return NO;
else
// logic to show or hide other things
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这种方法不再有效(至少在UIWebView子类中).canPerformAction:withSender:为除copy之外的每个系统菜单项调用:因此结果是始终显示系统复制菜单项.这意味着如果您有多个自定义菜单项,它们始终隐藏在"更多..."后面
那么,有没有办法真正删除系统的复制项目或一些替代方法,以防止菜单项隐藏在"更多......"后面?
更新
这是我覆盖canPerformAction时得到的输出:withSender:注意该方法永远不会被调用为"copy:"动作:
cannot perform action cut: with sender <UIMenuController: 0x7227d30>.
cannot perform action select: with sender <UIMenuController: 0x7227d30>.
cannot perform action selectAll: with sender <UIMenuController: 0x7227d30>.
cannot perform action paste: with sender <UIMenuController: 0x7227d30>.
cannot perform action delete: with sender <UIMenuController: 0x7227d30>.
cannot perform action promptForReplace: with sender <UIMenuController: 0x7227d30>.
cannot perform action _showMoreItems: …
Run Code Online (Sandbox Code Playgroud) 在MFC程序中,您可以通过检查应用程序快捷方式的值来确定应用程序快捷方式是否将"运行"值设置为"最小化" m_nCmdShow
.在c#中有相同的方法吗?
为了澄清,我不想设置特定表单的状态.如果查看快捷方式的属性,则会显示"运行"选项.您可以将此值设置为"正常窗口","最小化"或"最大化".
在C++中,您可以通过查看来读取设置的启动值m_nCmdShow
.我需要在C#中做同样的事情.
更新
这个尝试:
[STAThread]
static void Main(string[] args)
{
ProcessStartInfo processInfo = Process.GetCurrentProcess().StartInfo;
MessageBox.Show(processInfo.WindowStyle.ToString());
...
}
Run Code Online (Sandbox Code Playgroud)
总是报告Normal
,无论快捷方式设置为什么.
我有一个包含NSBox控件的窗口.在那个NSBox是几个其他控件,(弹出窗口,文本字段等...)
我在同一个NIB文件中有另外两个NSBox,这些文件中充满了我想在特定条件下与第一个交换的控件.我希望这会发生一个很好的交叉淡入淡出效果,所以我做了以下几点:
在NSWindowController的-awakeFromNib
方法中:
[[self.myWindow contentView] setWantsLayer:YES];
Run Code Online (Sandbox Code Playgroud)
在我正在切换视图的方法中,我使用以下代码:
[[[self.myWindow contentView] animator] replaceSubview:previousView with:newView];
Run Code Online (Sandbox Code Playgroud)
这很好,视图交叉淡出就像我期望的那样.问题是对视图的控制有时会消失,没有明显的原因.它并不总是相同的视图(尽管NSPopUpButtons似乎特别容易出现这种情况),并且它们通常在有焦点时重新出现.
我是否还必须支持所有控制层?
更新:在显式分组中包装动画没有任何区别.在Nib文件中打开setWantsLayer也没有什么区别,但有趣的是,当我这样做时,NSPopupbuttons消失,直到点击其包含视图.在NSPopupbuttons上手动设置Layer也没有什么区别.
似乎其他人遇到了这个问题,但我找不到任何解决方案:
http://www.cocoabuilder.com/archive/message/cocoa/2008/3/30/202691 http://www.cocoabuilder.com/archive/message/cocoa/2008/4/25/205134
我需要将NSProgressIndicator中的图像放入NSOutlineView Cell中.我已经编写了代码,为确定的指标执行此操作,它的工作效果非常好:
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:NO];
[progressIndicator setMaxValue:100.0];
[progressIndicator setDoubleValue:somePercentage];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
Run Code Online (Sandbox Code Playgroud)
我试图修改代码也给我不确定的指标图像.然而,对于不确定的情况,我总是得到一个空白的16x16图像.(我已经通过在每种情况下将图像写入文件来确认这一点,确定的情况给出了进度指示器图像,不确定的情况总是16x16白色方块).
修改后的代码是:
if(self.lengthUnknown)
{
NSProgressIndicator *progressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 16, 16)];
[progressIndicator setStyle:NSProgressIndicatorSpinningStyle];
[progressIndicator setIndeterminate:YES];
NSImage *updateImage = [[NSImage alloc] initWithData:[progressIndicator dataWithPDFInsideRect:[progressIndicator frame]]];
[progressIndicator release];
return [updateImage autorelease];
}
else
{
// Same code as the first listing, this case works fine
}
Run Code Online (Sandbox Code Playgroud)
不确定的进度指标是否使用某种类型的绘图导致-dataWithPDFInsideRect:无法捕获其图像?
更多信息:我尝试将进度指示器设置为不使用线程动画以及尝试通过NSImage的lockFocus方法获取内容,如下所示,但这些尝试都没有产生任何影响.
Dave在 …
我有一个 UIViewController,其中我将 CALayer 子类添加到视图层:
[self.view.layer addSublayer:myObject.backgroundLayer];
Run Code Online (Sandbox Code Playgroud)
当我旋转设备时,视图会旋转,但 CALayer 不会旋转。它有点被分流到左边,仍然是纵向视图。
有没有办法让子图层自动旋转或者我需要应用变换?