使用弧,初始化后我的ivars为空 [英] using arc, my ivars are null after init

查看:66
本文介绍了使用弧,初始化后我的ivars为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

进行新的测试: 我放置了NSLog(@"%p", self.myArray); 数组分配后,我看到一个实际记录的地址.....!?!?!

MOST NEW TESTING: I placed a NSLog(@"%p", self.myArray); after the array assignment and I am seeing a address actually logged.....!?!?!

2012-03-06 01:33:52.618 ArrayTest[9883:f803] 0xae0f160

如果Xcode在局部变量或工具提示突出显示方法中看不到该ivar的地址,则似乎全部被淘汰了.

Seems that Xcode is all wacked out if it cant see the addess of that ivar in either local variables or with the tool tip highlight method...

有想法吗?

最新测试: 我创建了一个全新的项目.

NEWEST TESTING: I created a brand new project.

看来,简单地将对象分配给ivars根本行不通.如果在分配新创建的数组后查看myArray的地址,则该地址为空.

It seems that simple assigning of objects to ivars is not working at all. If I look at the address of myArray after the assignment of the newly created array it has a null address.

nslog的输出

2012-03-06 01:30:37.283 ArrayTest[9848:f803] (
)
(lldb) 

//
//  ViewController.h
//  ArrayTest
//
//  Created by Ben J Brown on 3/6/12.
//  Copyright (c) 2012StudioBflat. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    NSMutableArray *myArray;

}

@property (strong) NSMutableArray *myArray;

@end


//
//  ViewController.m
//  ArrayTest
//
//  Created by Ben J Brown on 3/6/12.
//  Copyright (c) 2012 StudioBflat. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

@synthesize myArray;

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSMutableArray *array = [NSMutableArray arrayWithCapacity:16];
    self.myArray = array;

NSLog(@%@",self.myArray); }

NSLog(@"%@",self.myArray); }

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

@end

旧数据:

在我的viewDidLoad中,我有:

In my viewDidLoad I have:

NSLog(@"%@",self.collectionOfImageViews);
    self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS];
     NSLog(@"%@",self.collectionOfImageViews);

但是,稍后当我访问该数组时,该数组具有一个地址,但是我添加到该数组中的所有对象均已消失,并且当我向该对象(NSMutableArray)发送计数消息时,它将在控制台中抛出该错误:

However later on when I access that array the array has an address but all the objects that I added to it are gone, and when I send a count message to that object(the NSMutableArray) it throws this in the console:

-[UIImage count]: unrecognized selector sent to instance 0x6b7ab40

我在界面中的属性:

@property(strong) NSMutableArray* collectionOfImageViews;

在@implmentation之后我有@synthesize collectionOfImageViews; ...我在这里想念什么?

and I have @synthesize collectionOfImageViews; right after my @implmentation... what am I missing here?

这是我收藏的地方:

  NSLog(@"%@",self.collectionOfImageViews);
    self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS];
     NSLog(@"%@",self.collectionOfImageViews);

在执行此操作后立即查看该数组,其地址为空....

looking at the array it has a null address right after this action....

关于我之前得到的那个奇怪的错误,我认为这是一个UIImage不响应计数...我通过更改接口中的ivar声明的顺序来解决该问题:

Concerning that earlier weird error where I had it consoling out that it was a UIImage not responding to count... I fixed that kinda by changing the order of the ivar declarations in the interface:

#import <UIKit/UIKit.h>
#import "TiledImageView.h"


@interface ViewController : UIViewController <TiledImageViewDelegation>
{

    NSMutableArray *collectionOfImageViews;
    UIImage *sourceImage;
    UIImageView *currentTappedView;
}



@property(strong) NSMutableArray* collectionOfImageViews;
@property(strong) UIImage* sourceImage;
@property(strong) UIImageView* currentTappedView;

@end

至于我稍后在哪里填充可变数组,则是该代码:

As for where I fill the mutable array later here is that code:

iView = [[TiledImageView alloc] initWithImage:[UIImage imageWithCGImage:tempImage]];
                iView.userInteractionEnabled = YES;
                iView.delegate = self;
                iView.contentMode = UIViewContentModeScaleAspectFit;
                [iView setTag:index];
                [iView setPosX:column];
                [iView setPosY:row];

            [collectionOfImageViews addObject:iView];

我很糊涂,因为这是简单的ivar设置和获取..以及分配和初始化...我之前已经做过很多次了,但是看来我的ivars并没有存活...我是新来的ARC.

I'm pretty darnd confused because this is simple ivar setting and getting.. and alloc and initialization... something I have done many times before but it seems my ivars are not staying alive... I'm new to ARC.

推荐答案

这似乎是LLDB错误.请改用GDB进行调试.

This seems to be an LLDB bug. Use GDB for debugging instead.

edit:这显然是lldb中的一个错误,我已经在3月提交了一个错误报告(它被标记为另一个错误的重复,后来被标记为已关闭)-该问题已在较新的Xcode版本中解决.

edit: It obviously is a bug within lldb, i have filed a bug report back in march (it was marked as a duplicate of another bug which was later marked as closed) - the issue has been resolved in newer Xcode versions.

这篇关于使用弧,初始化后我的ivars为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆