我有一个表格视图,其中的单元格用:
创建- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"GalleryCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSMutableArray *gallery = [gallerys objectAtIndex:indexPath.row];
cell.textLabel.text = [gallery objectAtIndex:1];
return cell;
}
我需要做的是在didSelectRowAtIndexPath中,触发segue以启动另一个视图,这也将使用prepareForSegue方法发送一些信息。
这个问题我不知道如何在故事板中创建要在此实例中使用的segue,我没有任何东西可以附加到它(没有按钮等)并且代码中创建了单元格,是吗也可以在代码中创建segue?或者还有另一种方法吗?
答案 0 :(得分:0)
推送视图控制器
[self performSegueWithIdentifier:@"yourSegueID" sender:self];
您可以按以下方式发送信息
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"yourSegueID"]) {
YourViewController *yourVC = segue.destinationViewController;
yourVC.information = myInformation;
}
}
答案 1 :(得分:0)
只需将segue从您的表拖到目标控制器并为其指定名称。 并在didSelectRowAtIndexPath调用
[self performSegueWithIdentifier:@"MySegue" sender:self];
然后跟随方法将被调用
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// here you can pass any value to new ViewController;
if ([segue.identifier isEqualToString:@"MySegue"]) {
YourNewViewController *VC = segue.destinationViewController;
VC.data = yourData;
}
}
答案 2 :(得分:0)
好的,您可以将它附加到您的表视图控制器,没有必要将它附加到按钮。只需转到故事板并执行以下操作: