也许这是一个非常简单的答案,但我到处搜索,似乎每个人都试图做与我正在做的相反的事情。我有一个定义如下的自定义UITableViewCell。如何停止覆盖UITableView边框线的自定义UITableViewCell
#import "TagCell.h"
#import "TagRepository.h"
#import "TagsViewController.h"
@implementation TagCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self setFrame:CGRectMake(0, 1, self.frame.size.width, 37)];
self.selectionStyle= UITableViewCellSelectionStyleNone;
self.textLabel.hidden=NO;
[self.textLabel setFrame:CGRectMake(self.bounds.size.width/2-40, self.bounds.origin.y+1, 300, 30)];
self.textLabel.text= @"test";
[self.textLabel setFont:[UIFont fontWithName:@"Helvetics" size:30] ];
}
return self;
}
-(void) layoutSubviews
{
NSArray *viewsToRemove = [self subviews];
for (UIView *v in viewsToRemove) {
if([v isKindOfClass:[UIButton class]])
{
[v removeFromSuperview]; //used to remove and redraw the button during a orientation change
}
}
UIButton * removeButton= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[removeButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:18] ];
[removeButton setFrame:CGRectMake(7*self.bounds.size.width/8, self.bounds.origin.y+3, 30, 30)];
removeButton.hidden=NO;
[removeButton addTarget:self action:@selector(removeTag) forControlEvents:UIControlEventTouchUpInside];
[removeButton addTarget:self action:@selector(removeTag) forControlEvents:UIControlEventTouchDragInside];
[removeButton setBackgroundImage:[UIImage imageNamed:@"button_red_unselect.png"] forState:UIControlStateNormal];
[removeButton setBackgroundImage:[UIImage imageNamed:@"button_red_select.png"] forState:UIControlStateSelected];
[removeButton setImage:[UIImage imageNamed:@"icon_minus.png"] forState:UIControlStateNormal];
[removeButton setImage:[UIImage imageNamed:@"icon_minus.png"] forState:UIControlStateSelected];
[self addSubview:removeButton];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void) removeTag
{
for(int i=0 ; i< [TagRepository instance].tags.count; i++)
{
if([self.textLabel.text isEqualToString:[TagRepository instance].tags[i]])
{
[[TagRepository instance].tags removeObjectAtIndex:i] ;
}
}
_reloadTable();
// [_delegate.table reloadData];
//RELOAD TABLE
}
@end
那么什么情况是,当我打通的tableview时,有一个活跃的自定义单元格边框是不存在的,它看起来好像有一个空白单元格下吧..什么的。
这是不希望的我希望单元格有一个边框。 包含表格的视图设置heightforcellatindex:indexpath = 40,以便委托函数返回40作为单元格高度值,我假设问题在于它与自定义单元格中的子视图之间存在某种不匹配。你看到这有什么问题?
请注意,我已经更改了Helvetica中的输入错误。
设置tableview的背景颜色,并确保你的tableviewcell启用了clipsToBounds – 2013-05-03 21:28:01
谢谢,但问题依然存在。 – user2317278 2013-05-03 22:20:54