テーブルのグループ化されたビューの作成に取り組んでいましたが、(驚くべきことに)それを達成しました。テーブル内の特定のセルを接続し、それを別のユニークなビューに接続できるようにしたいと考えていました。私はこれを行う方法に完全に困惑しています:/。これが私のコードです:
TableViewController.m
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
TableSectionArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
return [TableSectionArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *SectionHeader = nil;
if (section == 0) {
SectionHeader = @"Section1";
}
if (section == 1) {
SectionHeader = @"Section2";
}
if (section == 2) {
SectionHeader = @"Section3";
}
return SectionHeader;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
TableContentArray = [NSArray arrayWithObjects:@"Name1", @"Name2", nil];
}
if (section == 1) {
TableContentArray = [NSArray arrayWithObjects:@"Name1", @"Name2", nil];
}
if (section == 2) {
TableContentArray = [NSArray arrayWithObjects:@"Name1", @"Name2", nil];
}
return [TableContentArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if(cell == nil)
{
cell = [UITableViewCell alloc];
}
cell.textLabel.text = [TableContentArray objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end