위의 의견, 나는 당신이 달성하기를 원하는 것에 대해 모호한 이해만을합니다. 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
이 코드 난 그냥 내 아주에서 프로젝트에서 추출로 매우 거칠고 초기 아이폰 일. 속성이 누락되었습니다.
이 코드를 사용하여 도움을 받으려면 코드를 좀 더 보여줘야 할 것입니다. [table reloadData]를 수행하고 전체 작업을 새로 고치는 경우에도 동일합니까? –
나는 설명을 변경했다 .. Thank Adam. – jacob
예 -'[tv reloaddata]'는 분명히 더 많은 코드입니다. – vikingosegundo