编辑:正如亚当华盛顿指出的那样,从Beta 6开始,这段代码按原样运行,所以这个问题已经不再适用了.
我正在尝试创建并迭代二维数组:
var array = Array(count:NumColumns, repeatedValue:Array(count:NumRows, repeatedValue:Double()))
array[0][0] = 1
array[1][0] = 2
array[2][0] = 3
array[0][1] = 4
array[1][1] = 5
array[2][1] = 6
array[0][2] = 7
array[1][2] = 8
array[2][2] = 9
for column in 0...2 {
for row in 0...2 {
println("column: \(column) row: \(row) value:\(array[column][row])")
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这是我得到的输出:
column: 0 row: 0 value:3.0
column: 0 row: 1 value:6.0
column: 0 row: 2 value:9.0
column: 1 row: 0 value:3.0
column: 1 row: 1 value:6.0
column: …Run Code Online (Sandbox Code Playgroud) 我有一个在循环中调用的方法,看起来像这样:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
UIImageView *background = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, PAGE_WIDTH, PAGE_HEIGHT)];
background.image = backgroundImg;
for (UIView *view in viewArray)
{
[background addSubview:view];
}
UIGraphicsBeginImageContext(background.frame.size);
[background.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
for (UIView *view in background.subviews)
[view removeFromSuperview];
background.image = nil;
[background release];
[image retain];
[pool drain];
[image autorelease];
return image;
Run Code Online (Sandbox Code Playgroud)
但是,根据Instruments Memory Monitor的说法,内存使用量会不断上升,直到循环结束才会下降.(它崩溃了.)
如果我将UIGraphicsBeginImageContext替换为UIGraphicsEndImageContext
UIImage*image = someotherimage;
然后内存不会出现峰值,但是在循环的每次迭代中都会被分配和减少,正如我所期望的那样,由于自动释放池.(它没有崩溃)
如果我只是注释掉renderInContext行,它可以正常工作.(不会崩溃)
因此看起来好像renderInContext以某种方式保留在图像上 - 我怎样才能让它释放它?或者任何替代建议请:)?
我有一个单例弹出窗口,因此一次只能显示一个弹出窗口。当我执行共享弹出框并选择“ AirPrint”时,共享弹出框会正确消失,并在其位置显示AirPrint弹出框。
但是,如果我再次按下共享按钮,则共享弹出窗口会显示在AirPrint弹出窗口的顶部。
我找不到引用AirPrint弹出窗口将其关闭的方法。
一些进一步的信息-我在屏幕底部的工具栏上有UIBarButtonItems,在屏幕顶部的NavigationBar的rightBarButtonItem中嵌套了四个UIBarButtonItems。
屏幕底部的UIBarButtonItems可以自动正确关闭AirPrint弹出窗口,但顶部的嵌套窗口则不会。
但是,如果我知道AirPrint弹出框的名称,则可以将其从顶部按钮的代码中删除。