我已經實現了用於刪除和歸檔文章(SHCTableViewCell)的「清除」應用程序樣式刷卡。它運作良好。現在我想在單元格上添加更多標籤,並且已經創建了自定義表格視圖單元格形式的xib文件。然後,我將它與我的自定義單元的類(使用滑動)相關聯。我給了xib單元一個標識符。自定義TableViewCell與新關聯的.xib單元格衝突
,在我的cellForRowAtIndexPath添加以下代碼:
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:@"SHCTableViewCell_inbox" bundle:nil] forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
嗯,不錯!現在我可以看到我的自定義標籤,但滑動不起作用。 什麼可能導致這場衝突?
InboxViewController.m
. . .
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ContentCell";
SHCTableViewCell_inbox *cell = nil;//[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell)
{
[tableView registerNib:[UINib nibWithNibName:@"SHCTableViewCell_inbox" bundle:nil] forCellReuseIdentifier:CellIdentifier];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
cell.textLabel.backgroundColor = [UIColor clearColor];
Article* article = [self.articles objectAtIndex:indexPath.row];
cell.blog.text = article.blog;
cell.rating.text = [NSString stringWithFormat: @"%ld", (long)article.rating];
cell.title.text = article.title;
[cell setBackgroundColor:[UIColor clearColor]];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.delegate = self;
cell.todoItem = article;
return cell;
}
. . .
XIB細胞文件:
編輯: 我認爲這是值得做的手勢識別器。 SHCTableViewCell_inbox具有initWithStyle:顯然,它永遠不會被調用。 下一行代碼位於initWithStyle中,負責手勢識別。 UIGestureRecognizer * recognitionizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan :)]; recognizer.delegate = self; [self addGestureRecognizer:Recognizer];
也許它並不涉及到這個問題,但你應該考慮移動'[的tableView registerNib:[UINib nibWithNibName:@ 「SHCTableViewCell_inbox」 捆綁:無] forCellReuseIdentifier:CellIdentifier];'到'viewDidLoad'。你不應該檢查單元格是否爲'nil',只需調用'cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];''。不要忘記'... forIndexPath:'你的代碼想念它。 – Keenle
嗨,謝謝。我做了這些改變。 – sermilion
「Custom TableViewCell與新關聯的.xib單元衝突」是什麼意思?你收到任何錯誤?或應用剛剛停止響應滑動手勢? – Keenle