1

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に設定されている場合)、スクロールしようとしてもテーブルビューがバウンスしません。なぜ跳ねないのですか?

4

1 に答える 1

6

理由を正確に説明することはできませんが、空のテーブルビューでの動作はかなり不安定に見えます。とにかく、tableView.bounces = YES手動で設定すると(たとえば-viewDidLoad、テーブルビューが属するビューコントローラのメソッドで)、このような問題が修正され、空の場合でもテーブルビューが常にバウンスするようになります。

于 2012-09-07T10:25:12.350 に答える