我正在努力创建一个表格分组视图,并且我完成了(令人惊讶的)。我希望能够连接表格中的任何给定单元格并将其连接到另一个独特的视图。我完全不知道如何做到这一点:/。这是我的代码:
表视图控制器.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