UITableViewController から UIViewController にセルをリンクしようとしていますが、各セルは異なる UIViewController を呼び出す必要があり (したがって、各ビュー コントローラーへのリンクを 1 つ作成する必要があると思います)、それらをリンクする方法がわかりません。ストーリーボードを通して。
これは私が今まで持っているものです:
MainView.h
@interface MainView : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *tableData;
}
@property (nonatomic, retain) NSArray *tableData;
@end
MainView.m
- (void)viewDidLoad
{
tableData = [[NSArray alloc] initWithObjects:@"1", @"2", @"3", @"4", nil];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIViewController *anotherVC = nil;
if (indexPath.section == 0) //here I've also tried to use switch, case 0, etc
{
if (indexPath.row == 0)
{
anotherVC = [[ViewForFirstRow alloc] init];
}
NSLog(@"anotherVC %@", anotherVC); // shows that anotherVC = ViewForFirstRow
[anotherVC setModalPresentationStyle:UIModalPresentationFormSheet];
[anotherVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self.navigationController pushViewController:anotherVC animated:YES];
}
}
@end
したがって、最初の行が選択されていて、UITableViewController を UIViewController (ViewForFirstRow) にリンクしていない場合、黒い画面が表示されます。
UITableViewController を ViewForFirstRow にリンクすると、ビューが開きますが、コードで使用した効果が[self.navigationController pushViewController:anotherVC animated:YES];
ないため、コードではなくリンクが原因でビューが呼び出されたように見えます[self.navigationController pushViewController:anotherVC animated:YES];
コードでビューを適切に呼び出すにはどうすればよいですか?また、そのためにストーリーボードでどのようなリンクを使用する必要がありますか? また、UITableViewController を複数の UIViewController (ViewForFirstRow、ViewForSecondRow、ViewForThirdRow など) にリンクするにはどうすればよいですか。
ありがとう!