我创建了一个自定义的tableView单元格,我可以看到我的tableView使用了期望的自定义单元格。现在的问题是我不能选择我的表格行。我尝试从- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
中显示控制台输出,但它从未被调用过。我很困惑。我不知道我做错了什么。下面是我的自定义单元格类:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
CGRect contentRect = self.contentView.bounds;
CGFloat boundsX = contentRect.origin.x;
_title = [[UILabel alloc]initWithFrame:CGRectMake(boundsX +70, 5, 100, 25)];
_title.textAlignment = UITextAlignmentLeft;
_title.font = [UIFont systemFontOfSize:14];
_details = [[UILabel alloc]initWithFrame:CGRectMake(boundsX + 70, 30, 100, 15)];
_details.textAlignment = UITextAlignmentLeft;
_details.font = [UIFont systemFontOfSize:10];
_duration = [[UILabel alloc] initWithFrame:CGRectMake(boundsX + 200, 10, 65, 15)];
_duration.textAlignment = UITextAlignmentRight;
_duration.font = [UIFont systemFontOfSize:10];
_price = [[UILabel alloc]initWithFrame:CGRectMake(boundsX + 180, 30, 80, 15)];
_price.textAlignment = UITextAlignmentRight;
_price.font = [UIFont systemFontOfSize:10];
_listingImage = [[UIImageView alloc]initWithFrame:CGRectMake(boundsX +10, 0, 50, 50)];
[self.contentView addSubview:_title];
[self.contentView addSubview:_details];
[self.contentView addSubview:_price];
[self.contentView addSubview:_duration];
[self.contentView addSubview:_listingImage];
[_title release];
[_details release];
[_duration release];
[_price release];
[_listingImage release];
}
return self;
}
以下是我的
tableView: cellForRowAtIndexPath:
函数:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomizedCell *cell = (CustomizedCell *) [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[CustomizedCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
// cell = [[[CustomizedCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
ADJListing *listing = [self.dataSource.listings objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell._title.text = listing.title;
cell._details.text = listing.details;
cell._price.text = [listing.price stringValue];
cell._duration.text = (NSString*) listing.start_datetime;
cell._listingImage.image = [UIImage imageNamed:@"picture.png"];
return cell;
}
再次分享我的
tableView:didSelectRowAtIndexPath:
方法。- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"data");
detailedVC = [[DetailedViewController alloc] init];
detailedVC.dataSource = self.dataSource;
[self.navigationController pushViewController:detailedVC animated:YES];
[detailedVC release];
}
任何帮助都将不胜感激。
谢谢, Vik