0
我有兩個UIButtons
,它們的作用類似於segmented control
。我也有兩個自定義UITableView cells
,我的用戶可以使用按鈕在兩種單元格之間切換。有誰知道我該怎麼做?下面是一些代碼:如何使用按鈕更改可用視圖中的單元格類型
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *videoCellID = @"videoCellID";
static NSString *commentCellID = @"commentCellID";
static NSString *relatedCellID = @"relatedCellID";
VideoDetailCell *videoCell;
if (indexPath.row == 0)
{
videoCell = (VideoDetailCell *)[tableView dequeueReusableCellWithIdentifier:videoCellID];
if (!videoCell)
{
videoCell = [VideoDetailCell generateCellWithInfo:nil];
videoCell.navigation = self.navigationController;
}
return videoCell;
}
else
{
if (videoCell.buttonSelected == 0)
{
self.cellType = 0;
CommentCell *commentCell = (CommentCell *)[tableView dequeueReusableCellWithIdentifier:commentCellID];
if (!commentCell)
{
commentCell = [CommentCell generateCellWithInfo:nil];
}
return commentCell;
}
else
{
self.cellType = 1;
RelatedCell *related = (RelatedCell *)[tableView dequeueReusableCellWithIdentifier:relatedCellID];
if (!related)
{
related = [RelatedCell generateCellWithInfo:nil];
}
return related;
}
}
}
的videoCell
是另一個自定義UITableViewCell
,但總是會在UITableView中的第一個單元格。有一個UIButton顯示commentCell
,一個顯示relatedCell
。