表视图在iOS7中不滚动
我在视图中有一个UITableView。我已将UITableView的大小拖动到一次仅显示4行。在将数据加载到UITableView的ViewController代码中,我生成了6个要加载到UITableView的项,因为我想验证它是否会滚动 但是,当我运行程序并在iOS模拟器中预览它时,它不会滚动。我已检查是否启用了滚动 以下是填充UITableView的代码:表视图在iOS7中不滚动,ios,objective-c,uitableview,ios7,Ios,Objective C,Uitableview,Ios7,我在视图中有一个UITableView。我已将UITableView的大小拖动到一次仅显示4行。在将数据加载到UITableView的ViewController代码中,我生成了6个要加载到UITableView的项,因为我想验证它是否会滚动 但是,当我运行程序并在iOS模拟器中预览它时,它不会滚动。我已检查是否启用了滚动 以下是填充UITableView的代码: #import "APFacebookFriendsViewController.h" @interface APFacebook
#import "APFacebookFriendsViewController.h"
@interface APFacebookFriendsViewController ()
@end
@implementation APFacebookFriendsViewController
@synthesize facebookFriendsTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// set View title
self.title = @"Facebook Friends";
// load Facebook friends
self.facebookFriends = [self getFacebookFriends:@"Test Facebook User"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.facebookFriends count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"CellIdentifier";
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell *cell = [self.facebookFriendsTableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
// Configure the cell
NSString *facebookFriend = [self.facebookFriends objectAtIndex:[indexPath row]];
[cell.textLabel setText:facebookFriend];
return cell;
}
- (NSMutableArray *)getFacebookFriends:(NSString *)facebookUser
{
// placeholder data
NSMutableArray *facebookFriendsArray = [NSMutableArray array];
[facebookFriendsArray addObject:@"Friend A"];
[facebookFriendsArray addObject:@"Friend B"];
[facebookFriendsArray addObject:@"Friend C"];
[facebookFriendsArray addObject:@"Friend D"];
[facebookFriendsArray addObject:@"Friend E"];
[facebookFriendsArray addObject:@"Friend F"];
// END placeholder code
return facebookFriendsArray;
}
@end
不看你的整个项目就很难判断你做错了什么。您可能想尝试以下几点: 确保表视图位于其他视图的顶部 检查表视图的userInteractionEnabled是否设置为true。 确保表视图的委托和数据源指向视图控制器。 尝试将表视图设置为完整大小,并查看它是否仍然没有滚动。如果是这样,可能您没有正确设置一个表视图属性。您可以尝试删除并重新添加表视图。
还有很多事情可能出错,正如我所说的,如果不查看您的项目,很难判断。1.检查您的表视图及其超级视图是否已将userInteractionEnabled设置为TRUE。
2.表视图所在的自定义视图比clipsToBounds=NO的表视图小,clipsToBounds=NO是一个子视图,它超出了其父视图的界限,且未与之交互。因此设置为clipsToBounds YES。将其插入viewDidLoad
table.delegate=self;
table.datasource=self;
我检查了视图及其超级视图是否启用了UserInteraction。我找到的唯一一个与clipToBounds相关的设置是Clip子视图,当我将这些视图拖到合适的位置时,它对视图启用,对其超级视图禁用。我尝试了选中和取消选中“剪辑子视图”选项,但这并没有影响任何事情。这会发生什么?原因是什么?我已经在故事板中设置了代理和数据源。感谢您的想法-尝试了它们,但仍然不起作用。