bounces
およびalwaysBounceVertical
プロパティがYESに設定されている限り、ユーザーがスクロールすると、UITableViewは(空の場合でも)バウンスする必要があります。UITableViewControllerを初期化すると、すべてが期待どおりに機能します。単純なビュー階層(単一のUITableView子を持つトップレベルUIView)を使用してペン先からロードされたUIViewControllerを初期化すると、テーブルビューはバウンスしなくなりました。これが私が使用したコードです:
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITableViewDataSource>
@end
@implementation AppDelegate
@synthesize window = _window;
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *rootViewController = nil;
UITableView *tableView;
BOOL loadFromNib = NO;
if (loadFromNib)
{
rootViewController = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
tableView = [rootViewController.view.subviews objectAtIndex:0];
}
else
{
rootViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
tableView = (UITableView *)rootViewController.view;
}
tableView.dataSource = self;
NSLog(@"%@ bounces: %@", tableView.class, tableView.bounces ? @"YES" : @"NO");
NSLog(@"%@ alwaysBounceVertical: %@", tableView.class, tableView.alwaysBounceVertical ? @"YES" : @"NO");
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
@end
loadFromNib
変数をYESまたはNOに設定してこのコードを実行すると、常に次のログが記録されます。
UITableView bounces: YES
UITableView alwaysBounceVertical: YES
しかし、ペン先からロードすると(つまりloadFromNib
、YESに設定されている場合)、スクロールしようとしてもテーブルビューがバウンスしません。なぜ跳ねないのですか?