2010-12-02 6 views
-1
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone]; 

이 후 나는 heightforRowAtIndexPath에서 1 셀의 높이를 증가하고있다. 그러나 놀랍게도 두 번째 셀의 높이가 증가하고 있지만 테이블 뷰를 스크롤하면 첫 번째 셀의 높이가 원하는대로 다시 설정됩니다. 작성으로있는 UITableViewCell reloadcellsAtIndexPaths는 다음과 같은 셀의 높이를 증가하지만 실제 하나

나는 내가 특정 셀을 경우에만 작동하지 않습니다 .. 잘 작동 [텔레비젼 reloaddata]를 사용하여 전체 테이블을 다시로드하면

이에 어떤 도움이 도움이 될 것입니다 ..

+0

이 코드를 사용하여 도움을 받으려면 코드를 좀 더 보여줘야 할 것입니다. [table reloadData]를 수행하고 전체 작업을 새로 고치는 경우에도 동일합니까? –

+0

나는 설명을 변경했다 .. Thank Adam. – jacob

+0

예 -'[tv reloaddata]'는 분명히 더 많은 코드입니다. – vikingosegundo

답변

0

위의 의견, 나는 당신이 달성하기를 원하는 것에 대해 모호한 이해만을합니다. I 은 높이를 변경하여 셀을 확장하려고한다고 가정합니다. 첫 번째 셀만 언급하면되지만, 클릭 할 때 모든 셀에 대해 수행 할 수 있기를 원합니다.

전체 프로젝트는 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 

이 코드 난 그냥 내 아주에서 프로젝트에서 추출로 매우 거칠고 초기 아이폰 일. 속성이 누락되었습니다.

관련 문제