我正在尝试制作一个调查应用程序。一个滚动视图中有 20 个视图和许多 uitextview。当我尝试这样做时,该应用程序的运行速度非常慢。我认为我无法正确进行内存管理。你能帮我做对吗?非常感谢。这是我的代码:
-(void)textViewBicimle: (UITextView *)textAlani{
[textAlani.layer setBorderColor:[[[UIColor blackColor] colorWithAlphaComponent:1.0] CGColor]];
[textAlani.layer setBorderWidth:1.0];
}
- (void) tableCiz:(NSMutableArray *)hucreler sutun:(int)sutunSayisi satir: (int)satirSayisi{
int z = 0;
for (int i =0;i<satirSayisi;i++){
for(int j=0;j<sutunSayisi&&z<satirSayisi*sutunSayisi;j++,z++){
[self textViewBicimle:[hucreler objectAtIndex:z]];
[[hucreler objectAtIndex:z] setFrame:CGRectMake((20+j*100), (20+i*40), 100, 40)];
}
}
}
-(void)hucreArrayOlustur: (int)sutunSayisi suankiView:(UIView *)soruViewIki satir:(int)satirSayisi{
for (int i = 0; i <sutunSayisi*satirSayisi; i++){
self.textView = [[UITextView alloc]init];
self.textView.text = @"dsgfdh";
[self.hucreArray addObject:self.textView];
[soruViewIki addSubview:self.textView];
[self.textView release];
}
}
-(void)viewOlustur{
for (int i = 0; i <soruAdedi; i++){
self.hucreArray = [[[NSMutableArray alloc]init]autorelease];
if (i == 0){
self.soruView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 728, 0)];
self.soruView.clipsToBounds = YES;
self.soruView.backgroundColor = [UIColor lightGrayColor];
[self hucreArrayOlustur:5 suankiView:self.soruView satir:10];
[self tableCiz:self.hucreArray sutun:5 satir:10];
CGRect frame = self.soruView.frame;
CGRect frame2 = [[self.hucreArray objectAtIndex:49] frame];
frame.size.height = frame2.origin.y+frame2.size.height+34;
self.soruView.frame = frame;
[self.viewArray addObject:self.soruView];
[scrollView addSubview:self.soruView];
[self.soruView release];
}
else{
CGRect frameGecici = [[self.viewArray objectAtIndex:i-1] frame];
float geciciY = frameGecici.origin.y+frameGecici.size.height+1;
self.soruView = [[UIView alloc]initWithFrame:CGRectMake(20, geciciY, 728, 0)];
self.soruView.clipsToBounds = YES;
self.soruView.backgroundColor = [UIColor lightGrayColor];
[self hucreArrayOlustur:5 suankiView:self.soruView satir:10];
[self tableCiz:self.hucreArray sutun:5 satir:10];
CGRect frame = self.soruView.frame;
CGRect frame2 = [[self.hucreArray objectAtIndex:49] frame];
frame.size.height = frame2.origin.y+frame2.size.height+34;
self.soruView.frame = frame;
[self.viewArray addObject:self.soruView];
[scrollView addSubview:self.soruView];
[self.soruView release];
}
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
scrollView.contentSize = CGSizeMake(0, 10000);
self.viewArray = [[NSMutableArray alloc]init];
[self viewOlustur];
NSLog(@"%@",self.viewArray);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[self.soruView release];
[self.textView release];
[scrollView release];
[super dealloc];
}
- (void)viewDidUnload {
[self setScrollView:nil];
[super viewDidUnload];
}
@end