【发布时间】:2011-02-14 04:21:03
【问题描述】:
我正在编写一个应用程序,该应用程序从服务器获取图像并将所有图像作为 UIButton 显示给用户,以便我可以拦截其上的事件。问题是,分配所有图像需要很长时间,当它最终显示所有图像时,应用程序在实际设备上崩溃(在模拟器上工作)。
在不崩溃的情况下分配这些图像对象的正确方法是什么?
提前致谢!
这是我当前的代码
for(start = 1; start <= limit; start++) {
NSString *tempstring;
if(start < 10) {
tempstring = [NSString stringWithFormat:@"0%d", start];
} else {
tempstring = [NSString stringWithFormat:@"%d", start];
}
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(displayThumbs:) object:[NSString stringWithFormat:@"%d", start]];
[queue addOperation:operation];
[operation release];
[queue release];
}
- (void)displayThumbs:(NSString *)buttoninfo {
int currentmag = [buttoninfo intValue];
currentmag--;
currentmag = (currentmag * 70) + 10;
NSString *tempstring;
if([buttoninfo intValue] < 10) {
tempstring = [NSString stringWithFormat:@"0%@", buttoninfo];
} else {
tempstring = [NSString stringWithFormat:@"%@", buttoninfo];
}
UIButton *magbutton = [[UIButton alloc] initWithFrame:CGRectMake(currentmag, 10, 50, 50)];
magbutton.tag = [buttoninfo intValue];
[magbutton setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_Page_%@.jpg", @"2011-02", tempstring]] forState:UIControlStateNormal];
[magbutton addTarget:self action:@selector(gotoStory:) forControlEvents:UIControlEventTouchUpInside];
[thumb_scoller addSubview:magbutton];
[magbutton release];
magbutton = nil;
}
【问题讨论】:
标签: iphone objective-c ios4 allocation