我用customcell做了一個tableview。單元格包括標籤和一個按鈕。問題是,如何在按下按鈕時檢測標籤的文本?Tableview自定義單元格按鈕
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
// Initialization code
primaryLabel = [[UILabel alloc]init];
primaryLabel.textAlignment = UITextAlignmentLeft;
primaryLabel.font = [UIFont systemFontOfSize:11];
primaryLabel.backgroundColor = [UIColor clearColor];
secondaryLabel = [[UILabel alloc]init];
secondaryLabel.textAlignment = UITextAlignmentLeft;
secondaryLabel.font = [UIFont systemFontOfSize:9];
secondaryLabel.backgroundColor = [UIColor clearColor];
myImageView = [[UIImageView alloc]init];
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:btn];
[self.contentView addSubview:primaryLabel];
[self.contentView addSubview:secondaryLabel];
[self.contentView addSubview:myImageView];
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
這並不難,但這取決於你如何設置單元格。您可以向我們展示您創建單元格,標籤和按鈕的代碼嗎? – sosborn
我也有一個提醒功能,我必須捕捉單元格內容並設置日曆的事件控制器。 – Ulvi