我按照教程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
我已經將它設置在界面生成器。我的問題是,我不知道如何告訴每個視圖,我添加了哪個組。 – 2011-03-04 01:14:43
我會在哪裏進行提示?我把它放在我的根視圖控制器中,但它說「部分」未聲明。請告訴我,如果我錯過了一些完全明顯的東西。 – 2011-03-04 01:27:02
您顯然需要閱讀一些Apple文檔。我提供的代碼將放在'cellForRowAtIndexPath'委託方法中。 – WrightsCS 2011-03-04 01:30:35