小编Bra*_*son的帖子

iOS:ARC,没有释放内存

我的iOS应用程序有点奇怪.一段时间后我的应用程序在内存中变低,因此内存警告,一切似乎都很好,但是当我检查内存使用情况时,我注意到所有对viewDidUnload的调用都没有释放大量内存,所以在我点击几下之后应用程序,它再次在内存警告,一切似乎再次正常,但没有很多内存已被释放,所以它再次在内存警告更快,然后它崩溃(大多数时间后第三个内存警告) .这个崩溃是随机的:应用程序冻结,应用程序离开,我的调试器说app暂停,但没有糟糕的访问或sigbort,没有僵尸.我的猜测是,内存警告无法释放足够的内存.

(我检查了所有viewDidUnload,并将每个在viewDidLoad中分配的对象设为nil)

任何帮助都会有用!

非常感谢.

memory memory-management ios automatic-ref-counting

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

使用ARC处理NSError - 泄漏

- (BOOL)parserJSONString:(NSString *)jsonString error:(NSError **)anError {
   //some data getting
   //error handle

    NSString *description = @"phone number couldn't be using";
    NSString *recoverySuggestion = @"Please provide an other phone number.";
    NSInteger errorCode = -1;
    NSArray *keys = [NSArray arrayWithObjects: NSLocalizedDescriptionKey, NSLocalizedRecoverySuggestionErrorKey, nil];
    NSArray *values = [NSArray arrayWithObjects:description, recoverySuggestion, nil];
    NSDictionary *userDict = [NSDictionary dictionaryWithObjects:values forKeys:keys];
    *anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];
    return NO;
}
Run Code Online (Sandbox Code Playgroud)

*anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];编译器给出下一个泄漏警告"潜在的空取消引用.根据'创建和返回NSError对象'中的编码标准,参数''可能为空"
如何解决这个问题?

iphone objective-c ipad ios automatic-ref-counting

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

应用不同的过滤器

我想问我正在使用核心图像并应用一些过滤器使用此过滤器

filter = [CIFilter filterWithName:@"CIVignette" 
                                  keysAndValues: kCIInputImageKey, beginImage, 
                        @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
    CIImage *outputImage = [filter outputImage];
Run Code Online (Sandbox Code Playgroud)

但我想知道我如何实现我试过的其他过滤器,但应用程序崩溃,所以我想应用像我使用日志内置的这些过滤器

    CISourceOutCompositing,
    CISourceOverCompositing,
    CIStraightenFilter,
    CIStripesGenerator,
    CITemperatureAndTint,
    CIToneCurve,
    CIVibrance,
    CIVignette,
    CIWhitePointAdjust
Run Code Online (Sandbox Code Playgroud)

现在我想应用这些过滤器.我应该使用哪种方法?

iphone core-image ios ios5

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

用于Retina iPad图像的正确后缀是什么?

对于仅限iPad的应用程序,添加到自动用于Retina显示屏的图像的正确后缀是什么?

例如:如果我有一个名为"myimage.png"的图像,那么Retina图像是否必须命名为:"myimage@2x.png"?

我只是想将所有的视网膜图像添加到Xcode项目中,如果是Retina iPad则自动使用/拍摄.

xcode ipad ios

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

来自线程的警报对话 - Android

我有一个线程,每六秒钟就会向数据库发送一次GPS坐标,并且我会检查用户是否在一个已定义的区域内.如果用户不在该位置,我想要一个警告对话框,通知他们他们超出范围,如果他们在该区域内,我想要一个告诉他们在范围内的对话框.我检查工作正常,但我已经尝试过,我很确定我无法在后台线程上添加对话框.我已经阅读了一些关于使用处理程序的内容,但我不确定如何实现它.如果您有任何建议我会很感激!谢谢.

这是我FindLocation.java从主要活动(MainActivity.java)调用的方式:

new FindLocation(getBaseContext()).start(usr_id1); //sends a user id with it
Run Code Online (Sandbox Code Playgroud)

下边是 FindLocation.java

public class FindLocation extends Thread {

public boolean inJurisdiction;
public boolean AlertNotice = false;
private LocationManager locManager;
private LocationListener locListener;

Context ctx;
public String userId;

public FindLocation(Context ctx) {
     this.ctx = ctx;
}

 public void start(String userId) {
        this.userId = userId;
        super.start();
      }

 @Override
public void run() {
     Looper.prepare();
    final String usr = userId;      

    //get a reference to the LocationManager
    locManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); …
Run Code Online (Sandbox Code Playgroud)

java multithreading android handler android-alertdialog

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

如何在Xcode中使用图像过渡滤镜?

在成功地遵循Ray Wenderlich网站的教程之后,我决定尝试操纵我学到的东西并将其应用于CITransition,特别是CIDissolveTransition.然而,即使在交叉引用我所学到的反对Apple自己的过滤器文档之后,我似乎也无法显示图像(我必须说,这些文档已过时并且非常难以在他们自己的复杂示例之外进行调整).这是我到目前为止:

NSURL *url = [NSURL fileURLWithPath:imagePath];
NSURL *url2 = [NSURL fileURLWithPath:image2Path];
CIContext *context;
CIFilter *filter;
CIImage *beginImage, *targetImage;
UIImageView *mainImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[self addSubview:mainImage];

beginImage = [CIImage imageWithContentsOfURL:url];
targetImage = [CIImage imageWithContentsOfURL:url2];

if(context == nil)
{
  NSLog(@"Creating Context");
  context = [CIContext contextWithOptions:nil];
}
if(filter == nil) {
  NSLog(@"Creating filter");
  filter = [CIFilter filterWithName:@"CIDissolveTransition" keysAndValues:@"inputImage",   beginImage, @"inputTargetImage", targetImage, @"inputTime", [NSNumber numberWithFloat:0.5], nil];
}

CIImage *outputImage = [filter outputImage];

CGImageRef cgimg = [context createCGImage:outputImage …
Run Code Online (Sandbox Code Playgroud)

image-processing objective-c core-image ios

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

iOS 5仅使用Release Build阻止崩溃

我已经使用了块和ARC,并且在某些情况下发现,iOS仅在Release版本中崩溃.编写代码是错误的方法,就像这样.

-(IBAction)clickedButtonA:(UIBarButtonItem*)sender event:(UIEvent*)event {
  NSMutableArray *arrRows = [NSMutableArray arrayWithCapacity:0];
  #warning this code only crash on Release Build.... Don't use this
  NSMutableDictionary * dicRow = [NSMutableDictionary dictionaryWithCapacity:0];
  [arrRows addObject:dicRow];
  dispatch_block_t block = ^{
    NSString *str = [NSString stringWithFormat:@"%@",[_tweet valueForKey:@"text"]];
    [[UIPasteboard generalPasteboard] setString:str];
  };
  [dicRow setValue:block forKey:kDicKeyLinkPopBlock];

  NSMutableArray *sections = [NSMutableArray arrayWithObject:arrRows];
  TOVLinkPopoverViewController *controller= [[TOVLinkPopoverViewController alloc] init];
  controller.arrayLink = sections;
}
Run Code Online (Sandbox Code Playgroud)

从其他控制器,当我访问该块时,它崩溃只有我在发布版本.我知道你需要复制块

[dicRow setValue:[block copy] forKey:kDicKeyLinkPopBlock];
Run Code Online (Sandbox Code Playgroud)

对于非块感知类,如NSMutableDictionary.

问题是"为什么它只会在发布版本上崩溃?" 我知道这应该"崩溃",这是使用块的错误方法,但希望它在Debug构建时崩溃,所以我们可以更早地找到这种bug.

还有一个问题是"是否存在任何使用调试版本使代码崩溃的构建设置?"

您可以从gitHub运行示例代码, https://github.com/tomohisa/iOS_PopoverMenu_Notification

请参阅ViewController.m并查找已注释掉的代码(仅在发布时崩溃).

ios objective-c-blocks automatic-ref-counting

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

使用XCODE 4.2在iOS 5.0编译中出现Libpng错误

当我尝试加载三角形时,我收到下一个错误:

Mesh_Mesh_Box001.001: 35: GL_TRIANGLE_STRIP libpng error: CgBI: unknown critical chunk

但这适用于另一个例子.

到底是怎么回事?

提前致谢.

opengl-es objective-c ios

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

在iOS 5核心图像过滤器中显示从CIImage获取的UIImage

我正在处理图像过滤器应用程序.我使用以下代码创建了过滤器:

context = [CIContext contextWithOptions:nil];



    beginImage = [[CIImage alloc] initWithImage:[UIImage imageNamed:@"biscus_small.png"]];


    filter = [CIFilter filterWithName:@"CISepiaTone" 
                                  keysAndValues: kCIInputImageKey, beginImage, 
                        @"inputIntensity", [NSNumber numberWithFloat:0.8], nil];
Run Code Online (Sandbox Code Playgroud)

然后当用户选择过滤器时,我只需在过滤器应用后获取CIImage并分配给UIImageView.由于某种原因,setImage之后的UIImageView显示为白色(无).

CIImage *outputImage = [filter outputImage];

   // CGImageRef cgimg = 
   // [context createCGImage:outputImage fromRect:[outputImage extent]];

    UIImage *finalImage = [UIImage imageWithCIImage:outputImage];

    [self.imageView setImage:finalImage];
Run Code Online (Sandbox Code Playgroud)

如果我使用CIContext的createCGImage方法然后它工作正常并使用过滤器显示图像但使用createCGImage非常慢.

core-image ios

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

通过选择器比较两个字符串:意外结果

我正在练习如何在Objective-C中使用选择器.
在这段代码中,我试图比较两个字符串:

int main (int argc, const char * argv[])
{
    @autoreleasepool
    {
        SEL selector= @selector(caseInsensitiveCompare:);
        NSString* str1=@"hello";
        NSString* str2=@"hello";
        id result=[str1 performSelector: selector withObject: str2];
        NSLog(@"%d",[result boolValue]);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

但它打印为零.为什么?

编辑:
如果我将str2更改为@"hell",我会得到一个EXC_BAD_ACCESS.

objective-c selector automatic-ref-counting

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