繁体   English   中英

TableView无法在iOS7中滚动

[英]TableView not scrolling in iOS7

我在View里面有一个UITableView 我将UITableView的大小拖动到一次仅显示4行。 在将数据加载到UITableViewViewController代码中,我生成了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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM