【发布时间】:2015-04-18 22:47:19
【问题描述】:
我正在尝试创建一个 tableView,如果您点击一个单元格,它会展开并显示为按钮。到目前为止我遇到的问题是,如果我用按钮创建单元格,然后说如果你按下它应该只有全高,它仍然显示按钮,但它们与 tableView 中的下一个单元格重叠
在点击之前应该隐藏的单元格部分是否真正做到了这一点?
这就是我在 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中是否添加了标签和按钮?尝试将单元格的内容视图设置为剪辑子视图。
-
类“ExpandingCell”与MainStoryboard中的prototypeCell相连
标签: ios objective-c uitableview overlapping