这里我在UITableViewCell中有一个按钮。如果我单击按钮,则应弹出另一个视图。如果我单击相同的按钮,则应禁用该视图。请帮帮我。提前谢谢。
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"];
cell.frame = CGRectZero;
cell.backgroundColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 250, 50)];
label.font = [UIFont lightFontWithSize:14];
label.textAlignment = NSTextAlignmentLeft;
label.textColor = [UIColor blackColor];
label.highlightedTextColor = [UIColor whiteColor];
label.numberOfLines = 2;
label.tag = 1;
ForumDBFilePath* currObj = [forumResultArray objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@",currObj.postcontent];
cell.textLabel.font = [UIFont regularFontWithSize:15];
[cell.contentView addSubview:label];
UIBackgroundButton* replyButton = [UIBackgroundButton buttonWithType:UIButtonTypeCustom];
[replyButton setButtonColor:[UIColor whiteColor] setBackgroundColor:[UIColor getNavBarColor]];
[replyButton setTitle:@"Reply" forState:UIControlStateNormal];
replyButton.tag = indexPath.row;
[replyButton.titleLabel setFont:[UIFont mediumFontWithSize:14]];
[replyButton setFrame:CGRectMake(viewWidth-0, 15, 125, 30)];
[replyButton addTarget:self action:@selector(replyButton:) forControlEvents:UIControlEventTouchUpInside];
[replyButton resignFirstResponder];
[cell.contentView addSubview:replyButton];
}
return cell;
}
答案 0 :(得分:0)
你可以像这样覆盖superview方法:
- (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
id hitView = [super hitTest:point withEvent:event];
if (hitView == self) {
return nil;
} else {
return hitView;
}
}
希望它对你有所帮助。