2010-06-03 89 views
1

帮帮我。 addSubview不起作用。 我想在scrollView上添加“ContentView”。 但是“ContentView”没有出现在屏幕上。 “ContentView”是UIView。无法正常工作。 addSubview问题

当我从[self.view addSubview:scrollView]更改为self.view = scrollView时, addSubview不起作用。

请教我如何在这个屏幕上添加UIView!

- (void)viewDidLoad { 
[super viewDidLoad]; 

scrollViewMode = ScrollViewModeNotInitialized; 
mode = 1; 
imageViewArray = [[NSMutableArray alloc] init]; 
mainStatic = [[MainStatics alloc] init];  
[mainStatic setSetting]; 
NSString* path = [[NSBundle mainBundle] pathForResource:@"Files" ofType:@"plist"];  
NSArray* dataFiles = [NSArray arrayWithContentsOfFile:path];  
kNumImages = [dataFiles count]; 

CGRect frame = [UIScreen mainScreen].applicationFrame; 
scrollView = [[touchClass alloc] initWithFrame:frame]; 
scrollView.delegate = self; 
scrollView.maximumZoomScale = 5.0f; 
scrollView.minimumZoomScale = 1.0f; 
[scrollView setBackgroundColor:[UIColor blackColor]]; 
[scrollView setDelegate:self]; 
scrollView.delaysContentTouches=NO; 
scrollView.userInteractionEnabled = YES; 
[scrollView setCanCancelContentTouches:NO]; 

NSUInteger i;             
for (i=0;i<[dataFiles count];i++) 
{ 
    UIImage* image = [UIImage imageNamed:[dataFiles objectAtIndex:i]]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
    imageView.contentMode = UIViewContentModeScaleAspectFit;     
    imageView.userInteractionEnabled = NO;         
    CGRect rect = imageView.frame;           
    rect.size.height = 480;         
    rect.size.width = 320;          
    imageView.frame = rect;             
    imageView.tag = i+1;                  
      [imageViewArray addObject:imageView]; 
} 

self.view = scrollView; 

[self setPagingMode]; 
UIView* contentView;            
CGRect scRect = CGRectMake(0, 436, 320, 44);      
contentView = [[UIView alloc] initWithFrame:scRect]; 
[contentView addSubview:toolView];        
[self addSubview:contentView];        

}

回答

0

来源尚不清楚。 你永远不会在UIImageView中使用数组。没有资料什么是toolView等... 请提供更详细的来源。 touchClassUIScrollView的一个子类?

我注意到在你的代码:

  1. 你不释放imageimageView。所有这些图像imageViews将泄漏。在循环结束时,你应该添加[imageView release];[image release];
  2. 我不认为这是送[self addSubview:contentView];尝试使用[self.view addSubview:contentView];
+0

谢谢。 请检查我的新评论。 – kyoheialfaromeo2010 2010-06-07 06:13:55

1

我用图像的排列如下功能不错的主意。 toolView是与UIToolbar UIView 。 所以我想添加工具栏到屏幕上。 是的,touchClass是UIScrollView的子类。 1.我明白了。我忘了发布这个。谢谢。 2.OK.我修改了这个,但“ContentView”没有出现。

还有另外一个原因吗?

- (void)setPagingMode { 

    CGSize pageSize = [self pageSize]; 
    NSUInteger page = 0; 
    for (UIView *view in imageViewArray){ 
     [scrollView addSubview:view]; 
     view.frame = CGRectMake(pageSize.width * page++, 0, pageSize.width, pageSize.height); 
    } 

    scrollView.pagingEnabled = YES; 
    scrollView.showsVerticalScrollIndicator = scrollView.showsHorizontalScrollIndicator = YES; 
    scrollView.contentSize = CGSizeMake(pageSize.width * [imageViewArray count], pageSize.height); 
    scrollView.contentOffset = CGPointMake(pageSize.width * currentPage, 0);  
    scrollViewMode = ScrollViewModePaging; 
}