2010-08-19 52 views
0

我有一個名爲「HaveScrollController」的viewController,這是這樣的:爲什麼UIScrollViewDelegate不起作用?

@interface HaveScrollController : UIViewController <UIScrollViewDelegate>{ 
    IBOutlet UIScrollView *scrollView; 
    IBOutlet UIView *firstView; 
    IBOutlet UIView *secondView; 
    IBOutlet UIView *thridView; 
    IBOutlet UIView *fourthView; 
} 


@property (retain, nonatomic) UIScrollView *scrollView; 
@property (retain, nonatomic) UIView *firstView; 
@property (retain, nonatomic) UIView *secondView; 
@property (retain, nonatomic) UIView *thridView; 
@property (retain, nonatomic) UIView *fourthView; 


@end 

與.m是這樣的:

@synthesize scrollView,firstView,secondView,thridView,fourthView; 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self.view addSubview:scrollView]; 

    scrollView.delegate = self; 
} 


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{ 
    NSLog(@"scroll detected"); 
} 

@end 

我做出了IB所有的連接已經。我想利用這個控制器在我的「TestAppController」,它是這樣的,它不使用IB,並生成界面使用代碼:

@interface TestAppController : UIViewController <UIScrollViewDelegate,UIActionSheetDelegate, UITextFieldDelegate> { 
    HaveScrollController *scollViewController; 
} 

的.M是在的loadView這樣的事情方法:

scollViewController = [[HaveScrollController alloc] initWithNibName:@"HaveScrollView" bundle:nil]; 

[mainCanvas addSubview: buttomScollViewController.view]; 
self.view = mainCanvas; 
[mainCanvas release]; 

當我嘗試滾動視圖,但「滾動檢測」未顯示。我做錯了什麼?謝謝。

回答

2

是否滾動到scrollView?它看起來像你忘了設置contentSize

scrollView.contentSize = CGSizeMake(320, 400); 

顯然,確保contentSize大於scrollView's框架,使滾動操作踢

+0

,但我已經做出IB滾動視圖已經.. – DNB5brims 2010-08-19 03:43:16

+0

雖然我很確定你仍然需要指定一個contentSize。我沒有看到在IB中指定的任何位置,因此您可能需要在代碼中執行viewDidLoad。 – dontGoPlastic 2010-08-19 03:49:04