0

我正在尝试制作一个调查应用程序,但尽管我使用的是 ARC,但我无法进行内存管理。我的应用程序导致内存泄漏。我收到内存警告。当我在界面生成器中静态地制作我的应用程序时,没有问题,但是当我以编程方式制作我的应用程序时,我遇到了内存问题。为什么会这样?这是我的代码:

#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
int soruAdedi = 20;
@interface ViewController ()

@end

@implementation ViewController
@synthesize scrollView2;
-(void)textViewBicimle: (UITextField *)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)scrollViewDidScroll:(UIScrollView *)scrollView{

}

-(void)hucreArrayOlustur: (int)sutunSayisi suankiView:(UIView *)soruViewIki satir:(int)satirSayisi{
    for (int i = 0; i <sutunSayisi*satirSayisi; i++){
        textView = [[UITextField alloc]init];
        textView.text = @"dsgfdh";
        [hucreArray addObject:textView];
        [soruViewIki addSubview:textView];
    }
}

-(void)viewOlustur{
    for (int i = 0; i <soruAdedi; i++){
        hucreArray = [[NSMutableArray alloc]init];
        if (i == 0){
            soruView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 728, 0)];
            soruView.clipsToBounds = YES;
            soruView.backgroundColor = [UIColor lightGrayColor];
            [self hucreArrayOlustur:5 suankiView:soruView satir:10];
            [self tableCiz:hucreArray sutun:5 satir:10];
            CGRect frame = soruView.frame;
            CGRect frame2 = [[hucreArray objectAtIndex:49] frame];
            frame.size.height =  frame2.origin.y+frame2.size.height+34;
            soruView.frame = frame;
            [viewArray addObject:soruView];
            [scrollView2 addSubview:soruView];
        }
        else{
            CGRect frameGecici = [[viewArray objectAtIndex:i-1] frame];
            float geciciY = frameGecici.origin.y+frameGecici.size.height+1;
            soruView = [[UIView alloc]initWithFrame:CGRectMake(20, geciciY, 728, 0)];
            soruView.clipsToBounds = YES;
            soruView.backgroundColor = [UIColor lightGrayColor];
            [self hucreArrayOlustur:5 suankiView:soruView satir:10];
            [self tableCiz:hucreArray sutun:5 satir:10];
            CGRect frame = soruView.frame;
            CGRect frame2 = [[hucreArray objectAtIndex:49] frame];
            frame.size.height =  frame2.origin.y+frame2.size.height+34;
            soruView.frame = frame;
            [viewArray addObject:soruView];
            [scrollView2 addSubview:soruView];
        }
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView2.delegate = self;
    scrollView2.contentSize = CGSizeMake(0, 8000);
    viewArray = [[NSMutableArray alloc]init];
    [self viewOlustur];
    // 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)viewDidUnload {
    [self setScrollView2:nil];
    [super viewDidUnload];
}
@end
4

0 回答 0