UITableViewCell不调用prepareForSegu

UITableViewCell不调用prepareForSegu

本文介绍了自定义UITableViewCell不调用prepareForSegue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义UITableViewCell,名为 EventCell

I have a custom UITableViewCell, called EventCell.

EventCell.h

#import <UIKit/UIKit.h>

@interface EventCell : UITableViewCell

@property (nonatomic, strong) IBOutlet UILabel *titleLabel;
@property (nonatomic, strong) IBOutlet UILabel *locationLabel;
@property (nonatomic, strong) IBOutlet UILabel *dateLabel;
@property (nonatomic, strong) IBOutlet UILabel *typeLabel;
@end

EventCell.m

#import "EventCell.h"

@implementation EventCell

@synthesize titleLabel, locationLabel, dateLabel, typeLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

以下是我设置单元格的方法。

Here is how I'm setting up my cell.

EventsMasterViewController.m

- (EventCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Event *myEvent;
    NSString *CellIdentifier = @"EventCell";
    EventCell *cell = (EventCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"EventCell" owner:nil options:nil];

    for (id currentObject in topLevelObjects)
    {
        if ([currentObject isKindOfClass:[EventCell class]])
        {
            cell = (EventCell *)currentObject;
            break;
         }
    }

    myEvent = [self.myEventsDataController objectInListAtIndex:indexPath.row];

    cell.titleLabel.text = myEvent.name;
    cell.locationLabel.text = myEvent.location;
    cell.typeLabel.text = @"Social";
    cell.layer.borderColor = [UIColor blackColor].CGColor;
    cell.layer.borderWidth = 1.0;

    return cell;
}

单元格格式正常,看起来完全符合我的要求。但是当我点击它时,单元格会突出显示蓝色并且不会转到下一个视图。我在prepareForSegue方法中放了一个断点,它甚至没有被调用。

The cell is being formatted great, it looks exactly as I need it to. But when I click on it, the cell highlights blue and doesn't segue to the next view. I put a breakpoint in my prepareForSegue method and it's not even getting called.

有没有办法手动调用prepareForSegue?如果是这样,我应该在哪里做。

Is there some way to call prepareForSegue manually? If so, where should I do that.

推荐答案

你需要实现

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



[self performSegueWithIdentifier:@"YourSegueIdentifier" sender:nil];


}

这篇关于自定义UITableViewCell不调用prepareForSegue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 20:02