2010-06-03 84 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; 
}