小编HG'*_*G's的帖子

这是释放记忆的好方法吗?

我已经在iPhone上编程了很长一段时间,并且在内存管理方面遇到了不好的经历.我想知道以下方式是否是释放内存的好方法.

int count = [someObject retainCount];

for (int i = 0; i < count; i ++) 
{
[someObject release];
}
Run Code Online (Sandbox Code Playgroud)

这种方法在UIWebViews我面临的一些情况下(特别是)是一种绝望的行为.变量的retainCount减少到零,这将释放它使用的内存.该方法有点脏,但是它有任何瓶颈吗?

iphone memory-management objective-c

9
推荐指数
4
解决办法
1179
查看次数

becomeFirstResponder减缓app

我有两个用于用户名和密码的文本字段和一个提交按钮.按下提交按钮时,将执行检查以查看是否键入了用户名和密码.如果不是,则显示警报消息,未输入值的字段成为第一响应者.

-(IBAction)loginPressed:(id)sender {


    if ([username.text length] == 0)
    {
        [self showAlert:@"Invalid Username/ Password"];
       [username becomeFirstResponder];
        return;
    }

    if ([password.text length] == 0)
    {
        [self showAlert:@"Invalid Username/ Password"];
      [password becomeFirstResponder];
        return;
    }
}
Run Code Online (Sandbox Code Playgroud)

我观察到,单击按钮时,按钮保持选定状态约1.5秒,然后显示警报.如果我注释掉该becomeFirstResponder方法,它可以毫无停顿地工作.但是我需要becomeFirstResponder在那里.我如何使用它加快速度?

iphone uitextfield

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

无法写入Plist

我有一个关于如何写一个plist的非常基本的问题.我在我的资源文件夹中添加了一个"Here.plist"文件.以下是我的代码:

NSString *path = [[NSBundle mainBundle]pathForResource:@"Here" ofType:@"plist"];

NSArray *array = [[NSArray alloc]initWithObjects:@"First", @"Second", @"Third", nil];

[array writeToFile:path atomically:YES];
Run Code Online (Sandbox Code Playgroud)

执行代码后,"Here.plist"仍为空.我甚至尝试使用NSDictionary如下:

NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:@"firstValue", @"First", @"secondValue", @"Second", @"thirdValue", @"Third", nil];

[dict writeToFile:path atomically:YES];
Run Code Online (Sandbox Code Playgroud)

我经历了很多教程和论坛,但它不适合我.我究竟做错了什么?我不知所措.

iphone plist

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