[英]TableView not scrolling in iOS7
我在View
里面有一个UITableView
。 我将UITableView
的大小拖动到一次仅显示4行。 在将数据加载到UITableView
的ViewController
代码中,我生成了6个项目加载到UITableView
,因为我想验证它是否可以滚动。
但是,当我运行该程序并在iOS Simulator中预览它时,它没有滚动。 我检查了滚动是否已启用( 屏幕截图 )。
以下是填充UITableView
的代码:
#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.检查您的表视图及superviews
,将userInteractionEnabled
设置为TRUE
。
2.表格视图位于其中的自定义视图小于带有clipsToBounds=NO
的表格视图,该子视图超出其父视图的范围且未与之交互。 因此设置为clipsToBounds
YES
。
将其插入viewDidLoad;
table.delegate=self;
table.datasource=self;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.