最新测试:
我放置了一个 NSLog(@"%p", self.myArray);
数组分配后,我看到一个实际记录的地址......!?!?!
2012-03-06 01:33:52.618 ArrayTest[9883:f803] 0xae0f160
如果 Xcode 在局部变量中或使用工具提示突出显示方法看不到该 ivar 的地址,那么它似乎就彻底崩溃了...
想法?
最新测试: 我创建了一个全新的项目。
似乎简单地将对象分配给 ivars 根本不起作用。如果我在分配新创建的数组后查看 myArray 的地址,它的地址为空。
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);
- (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
旧数据:
在我看来DidLoad我有:
NSLog(@"%@",self.collectionOfImageViews);
self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS];
NSLog(@"%@",self.collectionOfImageViews);
但是稍后当我访问该数组时,该数组有一个地址,但我添加到其中的所有对象都消失了,当我向该对象(NSMutableArray)发送计数消息时,它会在控制台中抛出此消息:
-[UIImage count]: unrecognized selector sent to instance 0x6b7ab40
我的界面中的属性:
@property(strong) NSMutableArray* collectionOfImageViews;
我在@implmentation之后有@synthesize collectionOfImageViews;
...我在这里缺少什么?
这是我制作集合的地方:
NSLog(@"%@",self.collectionOfImageViews);
self.collectionOfImageViews = [[NSMutableArray alloc] initWithCapacity:NUMBER_OF_COLUMNS*NUMBER_OF_ROWS];
NSLog(@"%@",self.collectionOfImageViews);
查看数组,在此操作之后它有一个空地址......
关于之前的奇怪错误,我安慰它是一个 UIImage 没有响应计数...我通过更改界面中 ivar 声明的顺序修复了这个问题:
#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
至于我稍后在哪里填充可变数组,这里是代码:
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 没有活着...我是新手弧。
最佳答案
这似乎是一个 LLDB 错误。使用 GDB 进行调试。
编辑:这显然是 lldb 中的一个错误,我在三月份提交了一份错误报告(它被标记为另一个错误的重复,后来被标记为已关闭) - 该问题已在较新的 Xcode 版本中得到解决。
关于iphone - 使用 arc,我的 ivars 在初始化后为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579650/