Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为iOS应用程序进行内存管理?_Ios_Xcode_Cocoa Touch_Memory - Fatal编程技术网

如何为iOS应用程序进行内存管理?

如何为iOS应用程序进行内存管理?,ios,xcode,cocoa-touch,memory,Ios,Xcode,Cocoa Touch,Memory,我使用故事板和弧形模式。这包括三个视图控制器。 每个视图控制器都有自己的类 VC1有Class1.h和Class1.m VC2有Class2.h和Class2.m 在每个m文件中,我创建图像视图并将图像添加到图像视图中。 然后我将这个图像视图添加到滚动视图中 在这种情况下,在我在class1中使用了大约200个图像之后,class2的图像就不能显示在图像视图中了 首先,我认为这是内存问题。 我认为它已达到内存限制,因此无法再添加其他图像 因此,我减小图像大小并重试(从300Mb减小到30Mb)。

我使用故事板和弧形模式。这包括三个视图控制器。
每个视图控制器都有自己的类

VC1有Class1.h和Class1.m
VC2有Class2.h和Class2.m

在每个m文件中,我创建图像视图并将图像添加到图像视图中。
然后我将这个图像视图添加到滚动视图中

在这种情况下,在我在class1中使用了大约200个图像之后,class2的图像就不能显示在图像视图中了

首先,我认为这是内存问题。
我认为它已达到内存限制,因此无法再添加其他图像

因此,我减小图像大小并重试(从300Mb减小到30Mb)。
但是,它没有起作用。我不知道。 我怎样才能解决这个问题?请给我指路

这是我的密码

- (void)viewDidLoad
{

[super loadView];
self.view.backgroundColor = [UIColor grayColor];

UIScrollView *ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height)];
ScrollView.pagingEnabled = YES;

NSInteger numberOfViews = 200;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;

    // Create a UIImage to hold Info.png
    UIImage *image1 = [UIImage imageNamed:@"Image-001.jpg"];
    UIImage *image2 = [UIImage imageNamed:@"Image-002.jpg"];

    UIImage *image13 = [UIImage imageNamed:@"Image-200.jpg"];

    NSArray *images = [[NSArray alloc] initWithObjects:image1,image2,...,image200,nil];

    UIImageView *ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
    [ImageView setImage:[images objectAtIndex:i]];

    [ScrollView addSubview:ImageView];
}
ScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

[self.view addSubview:ScrollView];
-(void)viewDidLoad
{
[超级加载视图];
self.view.backgroundColor=[UIColor grayColor];
UIScrollView*ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,44,self.view.frame.size.width,self.view.frame.size.height)];
ScrollView.PaginEnabled=是;
NSInteger numberOfViews=200;
对于(int i=0;i

}为每个图像创建单独的
UIImageView
(具有适当大小),并将所有
UIImageView
添加到
UIScrollView
中,并给出
UIScrollView
的适当
contentSize

取变量
intx并在.h文件中声明
并赋值
x=0
viewDidLoad
方法中

然后给出适当的UIImageView框架

- (void)viewDidLoad
{

[super viewDidLoad];
self.view.backgroundColor = [UIColor grayColor];

x=0;

UIScrollView *ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height)];
ScrollView.pagingEnabled = YES;

NSInteger numberOfViews = 200;
for (int i = 0; i < numberOfViews; i++) {
    CGFloat xOrigin = i * self.view.frame.size.width;

    // Create a UIImage to hold Info.png
    UIImage *image1 = [UIImage imageNamed:@"Image-001.jpg"];
    UIImage *image2 = [UIImage imageNamed:@"Image-002.jpg"];

    UIImage *image13 = [UIImage imageNamed:@"Image-200.jpg"];

    NSArray *images = [[NSArray alloc] initWithObjects:image1,image2,...,image200,nil];

    UIImageView *ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height-44)];
    [ImageView setImage:[images objectAtIndex:i]];

    [ScrollView addSubview:ImageView];

    x= x + imageView.frame.size.width;

}
ScrollView.contentSize = CGSizeMake(imageView.frame.size.width * numberOfViews, self.view.frame.size.height);

[self.view addSubview:ScrollView];

}
-(void)viewDidLoad
{
[超级视图下载];
self.view.backgroundColor=[UIColor grayColor];
x=0;
UIScrollView*ScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,44,self.view.frame.size.width,self.view.frame.size.height)];
ScrollView.PaginEnabled=是;
NSInteger numberOfViews=200;
对于(int i=0;i
  • 检查是否将imageview添加到scrollview或self.view

  • 检查滚动视图框架或滚动视图内容大小。要向UIScrollView生成n个图像,您可以这样做

  • 在for循环外部声明并添加数组对象,这样会占用编译器时间

  • UIScrollView*scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.size.width,self.view.size.height)];[self.view addsubView:滚动]

    浮动x轴=10


    对于(int i=0;i为什么要初始化imageArray 200次

    为什么以下部分在for循环中::

    // Create a UIImage to hold Info.png
    UIImage *image1 = [UIImage imageNamed:@"Image-001.jpg"];
    UIImage *image2 = [UIImage imageNamed:@"Image-002.jpg"];
    
    UIImage *image13 = [UIImage imageNamed:@"Image-200.jpg"];
    
    NSArray *images = [[NSArray alloc] initWithObjects:image1,image2,...,image200,nil];
    

    在for循环开始之前,只需初始化一次图像数组,然后迭代这些图像以添加到滚动视图中

    输入最大代码以了解更多信息如果您的问题不清楚,请尝试重新措辞或添加一些code@iPatel,抱歉,我的问题不完整。我在将图像添加到中时遇到问题图像视图。我认为这是内存问题。但是,我不知道如何解决它。@Dhruv Goei,很抱歉我的问题不完整。我在将图像添加到图像视图中时遇到了问题。我认为这是内存问题。但是,我不知道如何解决它。wt是否显示在输出中???重叠图像???