UITableViewCell reloadcellsAtIndexPaths увеличивает высоту следующей ячейки, но не фактической - PullRequest
0 голосов
/ 03 декабря 2010
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];

после этого я увеличиваю высоту 1-й ячейки в heightforRowAtIndexPath. Но, к моему удивлению, это увеличивает высоту второй ячейки, но когда я прокручиваю представление таблицы ... высота первой возвращается к желаемой.

Если я перезагружаю всю таблицу, используя [tv reloaddata], она работает нормально .. не работает, только если я делаю конкретную ячейку

Любая помощь по этому вопросу будет полезна ..

1 Ответ

0 голосов
/ 03 декабря 2010

Как написано в комментариях выше, у меня есть только смутное понимание того, чего вы хотите достичь. Я предполагаю , что вы хотите расширить ячейку, изменив их высоту. Вы просто упомянули первую ячейку, но я думаю, вы хотите иметь возможность сделать это для любой ячейки при нажатии.

Полный проект доступен на github

.h

#import <UIKit/UIKit.h>


@interface FirstViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    NSIndexPath *selectedIndexPath;
    NSDictionary *articles;
}

@end

.m

#import "FirstViewController.h"
@implementation FirstViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    selectedIndexPath = nil;
    articles = [[NSDictionary dictionaryWithObject:[NSArray arrayWithObjects:@"one", @"two", @"three",
                                                    @"four", @"five", @"six",
                                                    @"seven", @"eight", @"nine",
                                                    @"ten", @"eleven", nil]
                 forKey:@"title"] retain];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {

}

- (void)dealloc {
    [selectedIndexPath release];
    [articles release];
    [super dealloc];
}

- (int)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[articles allKeys] count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return [[articles allKeys] objectAtIndex : section];
}

- (int)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    id key = [[articles allKeys] objectAtIndex:section];
    return [[articles objectForKey : key] count];
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ((selectedIndexPath != nil) && (selectedIndexPath.row == indexPath.row))
        return 80.0;
    return 40.0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * MyIdentifier = @"MyIdentifier";
    UITableViewCell * cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
    }
    id key = [[articles allKeys] objectAtIndex:indexPath.section];
    cell.textLabel.text = [[articles objectForKey:key] objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (selectedIndexPath == indexPath) {
        selectedIndexPath = nil;
    } else {
        selectedIndexPath = indexPath;
    }
    [self.tableView deselectRowAtIndexPath : indexPath animated : NO];
    [tableView beginUpdates];
    [tableView endUpdates];
}

@end

Этот код довольно грубый, поскольку я только что извлек его из проекта в мои самые ранние iPhone-дни. то есть свойства отсутствуют.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...