也許這是一個非常簡單的答案,但我到處搜索,似乎每個人都試圖做與我正在做的相反的事情。我有一個定義如下的自定義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