1

助けて。addSubview は機能しません。scrollViewに「ContentView」を追加したい。しかし、「ContentView」は画面に表示されません。「ContentView」はUIViewです。

[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];                              

}

4

2 に答える 2

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;
}
于 2010-06-07T06:11:32.020 に答える
0

ソースは明らかではありません。UIImageView で配列を使用することはありません。toolView などの情報はありません。より詳細なソースを提供してください。touchClassのサブクラスですかUIScrollView?

あなたのコードで気づいたこと:

  1. imageあなたはリリースしませんimageView。このすべての画像 imageViews がリークされます。ループの最後に追加する必要が[imageView release];あります[image release];
  2. 送るのは得策ではないと思います[self addSubview:contentView];使ってみてください[self.view addSubview:contentView];
于 2010-06-03T11:46:35.563 に答える