我的表格視圖中有多個單元格;例如貓細胞,狗細胞,雞細胞。在貓細胞中,我有兩個視圖:圖形視圖和圖像視圖。表格單元格高度
如果圖表視圖隱藏並且圖像視圖可見,那麼我想將單元格高度設置爲200,在相反的情況下設置350。
我該怎麼做到這一點?我在表格視圖的heightForRowAt
委託方法中註冊了我的筆尖文件,並且我嘗試了不同的東西而無濟於事。這些都是在我的細胞中的兩種觀點:
@property (weak, nonatomic) IBOutlet UIView *imagesView;
@property (weak, nonatomic) IBOutlet UIView *graphView;
...這是我heightForRowAt
方法:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
TrainingImageCell *cell = (TrainingImageCell*)[self.tableView dequeueReusableCellWithIdentifier:@"TrainingImageCell"];
if (cell.isGraphViewOnTop == YES) {
return 350;
}
else {
return 200;
}
return 200;
}
爲什麼要在heightForRowAt中註冊nib文件。您正在註冊新單元,因此無法訪問退出的單元。如果你希望它在你的樣式中工作,而不是在IndexPath中爲行註冊新的單元格,你可以使用indexPath作爲TrainingImageCell * currentCell =(TrainingImageCell *)[tableView cellForRowAtIndexPath:indexPath];來訪問現有的單元格。並檢查屬性。 – luckyShubhra
在heightForRowAtIndexPath中使用dequeueReusableCellWithIdentifier方法並非有效。因爲首先調用heightForRowAtIndexPath方法,然後調用cellForRowAtIndexPath方法。如果你向我展示一些cellForRowAtIndexPath方法的代碼,我可以幫助你。 –
我得到了那部分@YagneshDobariya我必須使用它像在答案中提到的,但我現在有問題重新加載tableview。我已經定義了一個bool屬性isShowingGraphView,並在註冊nib後隱藏和取消隱藏cellForRowAt中的視圖。即時調用heightforRowAt這個屬性和布爾返回高度,但如果我打電話重新加載TableView整個視圖消失。 –