我有一個自定義的UITableViewCell,名爲EventCell
。自定義的UITableViewCell不能調用prepareForSegue
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
下面是我如何設置我的手機。
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方法中放置了一個斷點,它甚至沒有被調用。
有沒有辦法手動調用prepareForSegue?如果是這樣,我應該在哪裏做。
你的'tableView:didSelectRowAtIndexPath:'? – Desdenova 2012-08-11 15:24:08
我沒有一種方法叫做,我需要實現嗎? – ardavis 2012-08-11 15:30:37
從我正在閱讀的內容中,我們不使用'prepareForSegue'來代替'didSelectRowAtIndexPath'嗎? – ardavis 2012-08-11 15:33:10