我想創建一個tableView,如果你點擊一個單元格,它展開並顯示按鈕。我到目前爲止的問題是,如果我用按鈕創建單元格,然後說它應該只有完全的高度,如果你按下它,它仍然會顯示按鈕,但它們與tableView中的下一個單元格重疊擴大UITableViewCell重疊
在點擊之前應該隱藏的單元部分是否存在這樣的情況?
這是我在viewController.m 的ExpandingCell.h可以在下面找到
#import "ViewController.h"
#import "ExpandingCell.h"
@interface ViewController() <UITableViewDelegate, UITableViewDataSource>
@property (copy, nonatomic) NSArray *titleArray;
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end
@implementation ViewController
ExpandingCell *cell;
int selectedIndex = -1;
- (void)viewDidLoad {
[super viewDidLoad];
self.titleArray = @[@"Apple", @"Orange", @"Banana", @"Kiwi", @"Melon", @"Strawberry", @"Blueberry", @"Peach"];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.titleArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"expandingCell";
cell = (ExpandingCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.titleLabel.text = self.titleArray[indexPath.row];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return 94;
} else {
return 54;
}
}
@end
的ExpandCell.h只是一些標籤和按鈕這些都對細胞
#import <UIKit/UIKit.h>
@interface ExpandingCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *titleLabel;
@property (strong, nonatomic) IBOutlet UILabel *scoreLabel;
@property (strong, nonatomic) IBOutlet UILabel *backgroundLabel;
@end
僅用於文本目的我已經設置了第一個單元格,就好像它已經在「tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath」方法中選擇一樣。
我得到的是一個表格視圖,其中第一個單元格完美地顯示其高度,然後剩下的單元格按鈕在下一個單元格上重疊。
(我想展示的截圖,但它說我需要10級的聲譽這樣做)
如果真的讓我很感謝幫助
請上傳一些代碼,以便我們幫助您。 –
你如何改變你的細胞高度?你重新加載它們並開始在heightForCellAtIndexpath中返回不同的高度嗎? –
您可以鏈接到屏幕截圖。故事板/ XIB中是否添加了標籤和按鈕?嘗試設置單元格的內容視圖以剪輯子視圖。 – Wain