自定义表格单元格不会滚动

时间:2014-06-02 07:50:21

标签: ios iphone uitableview cell

您好我正在使用自定义单元格。但我无法滚动这个东西。它显示正确的内容,我已设置单元格高度,似乎已为表格视图检查了正确的选项,如启用滚动和反弹,但没有。包括一些代码。任何帮助都会非常棒。

#import "MainViewController.h"
#import "SWRevealViewController.h"
#import "StudentListTableViewCell.h"


@interface MainViewController ()

@end

@implementation MainViewController


{
    NSArray *NameLabel;
    NSArray *ProgrammeLabel;
    NSArray *CourseLabel;


}

- (void)viewDidLoad
{
    // Change button color
    //_sidebarButton.tintColor = [UIColor colorWithWhite:0.96f alpha:0.2f];

    // Set the side bar button action. When it's tapped, it'll show up the sidebar.
    _sidebarButton.target = self.revealViewController;
    _sidebarButton.action = @selector(revealToggle:);

    // Set the gesture
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];



    // Initialize Name
    NameLabel = [NSArray arrayWithObjects:@"Sung Tepper", @"Hannah  Zetterberg", @"January Orduna", @"Obdulia Rambin", @"Marhta Mcgonigal", @"Scarlett Bardsley", @"Sung Tepper", @"Hannah  Zetterberg", @"January Orduna", @"Obdulia Rambin", @"Marhta Mcgonigal", @"Scarlett Bardsley", nil];

    ProgrammeLabel = [NSArray arrayWithObjects:@"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", @"SABET 2014", nil];

    // Initialize Course
    CourseLabel = [NSArray arrayWithObjects:@"BP12", @"BP12", @"BP12", @"BP12", @"BP12", @"BP12",@"BP12", @"BP12", @"BP12",@"BP12", @"BP12", @"BP12", nil];

    self.title = @"News";

    [super viewDidLoad];    

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [NameLabel count];



}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *StudentListTableViewCellIdentifier = @"StudentListCell";

    StudentListTableViewCell *cell = (StudentListTableViewCell *)[tableView dequeueReusableCellWithIdentifier:StudentListTableViewCellIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StudentListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }


    cell.NameLabel.text = [NameLabel objectAtIndex:indexPath.row];
    cell.ProgrammeLabel.text = [ProgrammeLabel objectAtIndex:indexPath.row];
    cell.CourseLabel.text = [CourseLabel objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:@"man60.jpg"];


    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80;
}

@end

1 个答案:

答案 0 :(得分:1)

问题是由于你的panGestureRecognizer而产生的,它没有将触摸传递给tableview。

这应该修复它 - 将此方法添加到MainViewController.m

  - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        UIView *touchedView = touch.view;

//check if the touch was received by table view
        if ([[NSString stringWithFormat:@"%@", [touchedView class]] rangeOfString:@"UITableView"].location != NSNotFound) {
            return NO;
        }
        return YES;
    }

不要忘记将gestureRecognizer的委托设置为self,并实施UIGestureRecognizerDelegate

viewDidLoad方法中,将您的班级设置为gestureRecognizer的代表:

self.revealViewController.panGestureRecognizer.delegate = self;

MainViewController.h文件中,执行此操作以实现UIGestureRecognizerDelegate:

@interface MainViewController <UIGestureRecognizerDelegate>