Правильный способ заключается в использовании источника данных для всего, что связано с представлением конкретной ячейки. Это пример реализации щелчков и расширения ячеек. На самом деле для разработчиков iOS это должен быть один из наиболее часто используемых шаблонов.
@interface MySitesViewController()
@property (strong, nonatomic) NSMutableArray *menuRows;
@end
@implementation MySitesViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_menuRows = [NSMutableArray array];
[_menuRows addObject:@{
@"title":"Some title",
@"type": @"MyCellType",
@"height":@(44)
}.mutableCopy];
[_menuRows addObject:@{
@"title":"Some title",
@"type": @"MyCellType",
@"height":@(44)
}.mutableCopy];
[_menuRows addObject:@{
@"title":"Some title",
@"type": @"MyCellType",
@"height":@(44)
}.mutableCopy];
[_menuRows addObject:@{
@"title":"Some title",
@"type": @"MyCellType",
@"height":@(44)
}.mutableCopy];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_menuRows count];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *data = _menuRows[indexPath.row];
return data[@"height"];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableDictionary *data = _menuRows[indexPath.row];
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:data[@"type"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *data = _menuRows[indexPath.row];
[tableView deselectRowAtIndexPath:indexPath animated: YES];
NSInteger height = ((NSNumber*)data[@"height"]).integerValue;
if(height == 44)
{
data[@"height"] = @(200);
}else
{
data[@"height"] = @(44);
}
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
@end
использовать этот ответ, это поможет вам в том, что вы хотите сделать. В этом вы найдете гармоничную библиотеку, которую вы хотите сделать. http://stackoverflow.com/questions/15442697/how-to-create-an-accordion-with-uitableview-under-a-uitableview – jogshardik
Как я хочу, чтобы эта программа работала, чтобы показать больше информации об этой конкретной ячейке когда вы нажимаете на него, вместо того, чтобы отображать больше ячейки. Будет ли использование гармоник лучше в этом случае? – sof