如何将tableView中的行连接到segue
问题描述:
我有两个viewController,ViewController和TableViewController。 ViewController有一个按钮,当按下时,TableViewController将启动。 TableViewContoller包含5行。如何将tableView中的行连接到segue
我想要做的是,当我只按下偶数行时,我应该回到ViewController。为了解决这个问题,我们可以使用unwindSegue,但我不知道如何让segue响应表中的偶数行。
请让我知道如何使一个行中挂SEGUE
下面表是TableViewController
代码代码:
#import "TableViewController.h"
@interface TableViewController()
@property NSArray *tableData;
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableData = [NSArray arrayWithObjects:@"Android",
@"iOS",
@"swift",
@"objective-c",
@"openCV",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section {
return [self.tableData count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"images.jpg"];
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
NSLog(@"%li", indexPath.row);
NSLog(@"%@", [self.tableData objectAtIndex:indexPath.row]);
}
@end
答
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:
(NSIndexPath *)indexPath {
if(indexPath.row % 2 == 0) {
// Even row...
}
}
你可以调用performSegueWithIdentifier in didSelectRowAtIndexPath –
@ReinierMelian但我无法将tableview链接到退出图标来创建一个un windsegue – user2121
在你的ViewController和你的目标控制器之间建立一个segue,并把一个标识符 –