小编Jos*_*ick的帖子

编译器说有内存泄漏,但我没有看到

所以我用Xcode做了那件事,你说分析它发现泄漏和东西,在这里,它说我漏了(在下面的代码中标出).

// Copy dictionary to memory
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"DataCategoriesDictionary" ofType:@"plist"];
NSDictionary *dataCategoriesDictionary = [[NSDictionary alloc] initWithContentsOfFile:filepath];
self.choices = [[NSMutableDictionary alloc] initWithDictionary:[dataCategoriesDictionary objectForKey:self.chosenCategory]]; // LINE 55
[dataCategoriesDictionary release]; // HERE, the compiler says "Potential leak of an object allocated on line 55"
Run Code Online (Sandbox Code Playgroud)

虽然它没有任何意义,我可以渗出了实例变量,我尝试添加释放语句也无妨和Xcode中仍然给了我同样的错误.还有什么我可以泄漏?

iphone xcode memory-leaks memory-management objective-c

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

"被调用的对象类型NSString不是函数或函数指针"错误?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.cellIdentifier = [self.brain returnCellIdentifier:indexPath];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:self.cellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    cell.textLabel.text = [self.brain enchantmentCellText:indexPath];

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

我不知道为什么我会收到这个错误.错误似乎来自我的光标所在的行.我该如何解决这个错误:

Semantic issue
Called object type 'NSString *' is not a function or function pointer
Run Code Online (Sandbox Code Playgroud)

xcode objective-c

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

如何防止"this"被事件处理程序反弹

我有一个JS对象,其中一个原型函数是一个点击的事件处理程序.调用该函数时,该this对象将设置为单击绑定的元素.我想this成为该函数所属对象的实例.这是可能的,如果是的话,我该怎么做?有或没有jQuery的解决方案对我来说是可以接受的,虽然我确信其余的SO会欣赏纯粹的JS解决方案.

我已经尝试过bind这个函数this,它被绑定到窗口而不是对象的实例.

我想要的示例:在此演示中(下面重复的代码),我想要一个单击按钮时显示"Bark"的警报.

var Dog = function () {
    this.sound = "Bark";
}

Dog.prototype = {
    sayHello: function (e) {
        if (typeof this.sound == "undefined") {
            alert("I don't know what sound I should make!\n" + this);
        } else {
            alert(this.sound);
        }
    }
}

var d = new Dog();
var elem = document.getElementById("click");
elem.addEventListener("click", d.sayHello);
Run Code Online (Sandbox Code Playgroud)

javascript this

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

如果我用retain定义一个NSString,然后对它调用alloc,我需要发布两次吗?自我是多么必要.在公共变量面前?

基本问题在这里.

在我的.h中说,我定义了一个NSString:

@interface MyGreatClass
@property (nonatomic, retain) NSString *myAwesomeString;
@end
Run Code Online (Sandbox Code Playgroud)

然后在我的.m中,我有以下代码:

@implementation MyGreatClass
@synthesize myAwesomeString
-(void)dealloc{
    [myAwesomeString release];
}
-(void)viewDidLoad{
    self.myAwesomeString = [[NSString alloc] initWithString:@"Yay"];
}
@end
Run Code Online (Sandbox Code Playgroud)
  1. 我漏了吗?我知道,我知道,只要你拨打retainalloc 上的方法,它通过一个增加内存计数器,你需要为每一个版本的语句retainalloc,所以我怀疑我这样做,但我只是确保,因为如果这是是的,我必须在我的应用程序中为一堆变量执行此操作.此外,如果你必须两次调用release,我在哪里调用第二个版本?我可以dealloc一个接一个地打电话给他们两个吗?

  2. self.当引用你所在的类的属性时,nesesarry如何在变量前面?如果你没有它会发生什么,以及什么时候需要呢?

memory-management objective-c

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

多个排序描述符

指定多个排序描述符时:

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:lastName, firstName, age, nil];
Run Code Online (Sandbox Code Playgroud)

假设lastName,firstName和age都是NSSortDescriptor类型,并且具有由其名称建议的密钥.

我只想了解当我这样做会发生什么.假设我有一些核心数据(例如人员列表),我使用这些排序描述符对其进行排序.它是否会先尝试对姓氏进行排序,然后如果姓氏相同,请尝试按名字排序(只是那些姓氏相同的记录),然后iff的名字和姓氏是相同的,它会尝试按年龄排序(仅适用于那些记录)作为最后的手段.或者它会按照姓氏对列表进行排序,然后返回并按名字再次排序,然后再返回并按年龄排序?

iphone core-data objective-c nssortdescriptor

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

这是什么意思:NSString*string = NO?@"aaa":@"bbb";

我正在阅读Dropbox API,我找到了这一行:

NSString* title = [[DBSession sharedSession] isLinked] ? @"Unlink Dropbox" : @"Link Dropbox";
Run Code Online (Sandbox Code Playgroud)

我以前从未见过这种语法?它叫什么,它是什么意思?我可以通过观察它来判断它的作用,但是有人可以告诉我它吗?

iphone cocoa objective-c ios

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