小编Tre*_*zar的帖子

为什么这是物体的潜在泄漏?

有人可以解释为什么我在这里得到"潜在的物体泄漏"警告吗?我不明白.谢谢!

-(Code) drawTo:(ContextClass *) trg
{
  CGColorSpaceRef rgbColorspace = CGColorSpaceCreateDeviceRGB();
  CGFloat values[4] = { getRed(colour),
                      getGreen(colour),
                      getBlue(colour), 1.0 };

  trg.storedColourRef = CGColorCreate(rgbColorspace, values);    

  CGColorSpaceRelease(rgbColorspace);

  return OK;
}    
Run Code Online (Sandbox Code Playgroud)

是因为我将对象存储在trg.storedColourRef中吗?...这是不同类别的财产:

@property (nonatomic, assign) CGColorRef storedColourRef;
Run Code Online (Sandbox Code Playgroud)

properties objective-c

3
推荐指数
1
解决办法
217
查看次数

didReceiveMemoryWarning - 如何区分警告级别

如何区分didReceiveMemoryWarning中的两个内存警告级别?

Received memory warning. Level=1
Received memory warning. Level=2
Run Code Online (Sandbox Code Playgroud)

我想警告用户发生了什么,但仅限于2级(更关键).有谁知道如何编码?

谢谢!

objective-c didreceivememorywarning ios

2
推荐指数
1
解决办法
1951
查看次数

从 UIWebView 中提取文本

我有一个加载了一个简单的 rtf 文件的 UIWebView。(包含一行“这是一个测试”)

UIWebView* webview = [[UIWebView alloc] initWithFrame:CGRectMake(5, 50, 310, 400)];
[[self view] addSubview:webview];
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"rtf"]isDirectory:NO]]];
NSString *html = [webview stringByEvaluatingJavaScriptFromString: @"all"];
NSLog (@"html:%@", html.debugDescription);
Run Code Online (Sandbox Code Playgroud)

“THIS IS A TEXT”行正确显示在 UIWebView 中。有谁知道是否可以将那行文本(或更多)提取到 NSString 或其他一些可访问的容器中?

我知道有:

NSString *html = [webview stringByEvaluatingJavaScriptFromString: @"document.documentElement.outerHTML"];
Run Code Online (Sandbox Code Playgroud)

但这(显然)在这里不起作用。有任何想法吗 ?我基本上是在尝试(假)将 rtf 文件转换为 iOS 上的 NSString。谢谢!

javascript objective-c uiwebview ios

2
推荐指数
1
解决办法
2563
查看次数

如何正确释放CF对象?

我有这种方法(别人写了!)

- (CGPDFDocumentRef)getPdf {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:@"myLocalFileName.pdf"];

    NSURL *pdfURL = [NSURL fileURLWithPath:pdfPath];

    CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);

    return pdf;
}
Run Code Online (Sandbox Code Playgroud)

现在,我运行了Analyze并获得三个内存泄漏警告:

Call to function 'CGPDFDocumentCreateWithURL' returns a Core Foundation object with a +1 retain count
Object returned to caller as an owning reference (single retain count transferred to caller)
Object leaked: object allocated and stored into 'pdf' is returned from a method whose name ('getPdf') does not start …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c core-foundation ios

2
推荐指数
2
解决办法
1690
查看次数

popoverviewController在iPhone上崩溃,适用于iPad

这里的菜鸟问题:

任何想法为什么这个代码:

UIViewController* popoverviewController = [[UIViewController alloc]init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];

[webViewnetwork loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"webView" ofType:@"html"]isDirectory:NO]]];
[popoverView addSubview:webViewnetwork];

popoverviewController.view = popoverView;
popoverviewController.contentSizeForViewInPopover = CGSizeMake (100, 100);

self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverviewController];
[self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Run Code Online (Sandbox Code Playgroud)

在iPad上工作正常,但在iPhone上崩溃?我正在尝试做与我的iPad版本相同的事情,即添加带有html格式文本的子视图.它在第7行(initWithContentViewController)崩溃(程序接收信号:SIGABRT)

谢谢!

objective-c uipopovercontroller ios

1
推荐指数
1
解决办法
720
查看次数

从html中提取文本到NSString

我有一个html字符串,我从这次调用中收到了UIWebView:

NSString *html = [webview stringByEvaluatingJavaScriptFromString: @"document.documentElement.innerHTML"];
Run Code Online (Sandbox Code Playgroud)

NSString的内容是:

<head>
  <meta name="viewport" content="width=508">
  <style type="text/css">
    img {max-width:100%;}
    div { margin-top: 0;margin-bottom: 0;font-family:Arial, sans-serif;}
    p{margin-top: 0;margin-bottom: 0;word-wrap:break-word;}
    table{border-collapse: collapse;}
    td{word-wrap:break-word;font-family:Arial;vertical-align:top;}
  </style>
  <style type="text/css" media="screen">
    .bumpedFont16 { font-size:1.6em; }
    .bumpedFont20 { font-size:2.0em; }
  </style>
</head>
<body>
  <div style="width:508;background-color:#FFFFFF; position:relative; overflow:hidden;word-wrap:break-word;min-height:830px; padding-left:20;padding-right:20;padding-top:20;padding-bottom:20;">
    <style type="text/css">
      .s0 {font-size: 12;font-family: Helvetica;color: rgb(0,0,0);}
      .s1 {direction:ltr;text-align: left;}
    </style>
    <p class="s1">
      <span class="s0">
        <span class="bumpedFont16">THIS IS A TEST</span>
      </span>
    </p>
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)

如何将html字符串中的"这是一个测试"作为纯文本从另一个NSString中获取而没有任何格式?谢谢!

html objective-c nsstring ios

1
推荐指数
1
解决办法
1719
查看次数