나는 here 자습서를 따라 테이블을 그룹화 된 모양으로 만드는 방법을 궁금해하고있었습니다.그룹화 된 테이블보기 Obj-C
예 :
그룹 1은 서브 뷰 하나와 서브 뷰 두
그룹 2 내가 인터페이스 빌더에서 유형을 전환하지만 그건 하나 개의 그룹을 보여줍니다
서브 뷰 세 포함이 포함되어 있습니다.
덕분에, 아담
(!) 참고 *이 나는 따라서 튜토리얼, 목표 C에서 완전히 새로운 오전.
편집이 나는, 인터페이스 빌더에서 코드
#import "RootViewController.h"
#import "SubViewOneController.h"
#import "SubViewTwoController.h"
@implementation RootViewController
#pragma mark -
#pragma mark View lifecycle
-(void)awakeFromNib {
views = [[NSMutableArray alloc] init];
SubViewOneController *subViewOneController = [[SubViewOneController alloc] init];
SubViewTwoController *subViewTwoController = [[SubViewTwoController alloc] init];
//Subview 1
subViewOneController.title = @"Subview One";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview One", @"title",
subViewOneController, @"controller",
nil]];
[subViewOneController release];
//Subview 2
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = @"Subview Two";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview Two", @"title",
subViewTwoController, @"controller",
nil]];
[subViewOneController release];
//Subview 3
subViewOneController = [[SubViewOneController alloc] init];
subViewOneController.title = @"Subview Three";
[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:
@"Subview Three", @"title",
subViewOneController, @"controller",
nil]];
[subViewOneController release];
UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
temporaryBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
[temporaryBarButtonItem release];
self.title = @"Basic Navigation";
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [views count];
}
//
//I think it goes somewhere in here
//
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewStyleGrouped reuseIdentifier:CellIdentifier];
}
cell.text = [[views objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIViewController *targetViewController = [[views objectAtIndex:indexPath.row] objectForKey:@"controller"];
[[self navigationController] pushViewController:targetViewController animated:YES];
}
- (void)dealloc {
[views dealloc];
[super dealloc];
}
@end
을 받고 추천으로 종료됩니다. 내 문제는 내가 각 그룹에 어떤 그룹을 추가 할 것인지 알려주는 방법을 모른다는 것입니다. –
어디에서 그런 뜻이됩니까? 내 루트보기 컨트롤러에 넣어 있지만 "섹션"선언되지 않은 말한다. 내가 뭔가 분명하게 분실했는지 말해줘. –
분명히 Apple 문서를 읽어야합니다. 내가 제공 한 코드는'cellForRowAtIndexPath' 델리게이트에 올 것입니다. – WrightsCS