只要bounces和alwaysBounceVertical属性设置为YES,当用户滚动时,UITableView就会弹跳(即使是空的).当我初始化UITableViewController时,一切都按预期工作.当我初始化从具有简单视图层次结构的nib加载的UIViewController:具有单个UITableView子级的顶级UIView时,表视图不再反弹.这是我使用的代码:
#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
Run Code Online (Sandbox Code Playgroud)
当我运行此代码并将loadFromNib变量设置为YES或NO时,它始终记录此:
UITableView bounces: YES
UITableView alwaysBounceVertical: YES
Run Code Online (Sandbox Code Playgroud)
但是当我从笔尖加载它(即loadFromNib设置为YES)时,当我尝试滚动时,表视图不会反弹.为什么不反弹?
我无法准确解释原因,但空表视图的行为似乎非常不稳定.无论如何,tableView.bounces = YES手动设置(例如在-viewDidLoad表视图所属的视图控制器的方法中)可以修复这些问题并确保表视图始终反弹,即使是空的.
| 归档时间: |
|
| 查看次数: |
1210 次 |
| 最近记录: |