【问题标题】:unable to navigate to Destination View Controller in Storyboard in IOS无法导航到 IOS 故事板中的目标视图控制器
【发布时间】:2013-12-08 05:41:40
【问题描述】:

嗨,我正在使用 storyborad 在 IOS 中创建 UI。eveything 很好,但它没有导航到下一个视图控制器。我正在使用如下代码

[self performSegueWithIdentifier:@"identifier" sender:self]; and 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if([segue.identifier isEqualToString:@"identifier"]){

      ViewController *destVC =(ViewController *) [segue destinationViewController];

   }

我的 Tableview 代表

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"InfoCell";


        HMSForumInfoCell *cell = (InfoCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"InfoCell" owner:self options:nil];
            cell = [nib objectAtIndex:0];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            NSLog(@"Cell created");
        }


        NSDictionary *detailsDic = [_filteredListOfForums objectAtIndex:indexPath.row];


        [cell.headLinesLabel setText:[detailsDic objectForKey:kTopic]];

         // Adding underlined Colored text using NSMutableAttributedString

        NSMutableAttributedString *commentString = [[NSMutableAttributedString alloc] initWithString:[detailsDic objectForKey:kCreatedby]];


        UIColor* textColor = [UIColor colorWithRed:255.0f/255.0f green:198.0f/255.0f blue:0.0f/255.0f alpha:1.0f];
        [commentString setAttributes:@{NSForegroundColorAttributeName:textColor,NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]} range:NSMakeRange(0,[commentString length])];

        [cell.nameButton setAttributedTitle:commentString forState:UIControlStateNormal];


   //     [cell.nameButton addTarget:self action:@selector(replyButtonAction:) forControlEvents:UIControlEventTouchUpInside];


        [cell.nameButton addTarget:self action:@selector(namebuttonPressed:) forControlEvents:UIControlEventTouchUpInside];


        [cell.replyButton addTarget:self action:@selector(replyButtonPressed:) forControlEvents:UIControlEventTouchUpInside];



        return cell;
    }

    - (void)replyButtonPressed:(id)sender {


            [self performSegueWithIdentifier:@"id1" sender:self];

    }

    - (void)namebuttonPressed:(id)sender {


        [self performSegueWithIdentifier:@"id2" sender:self];


    }

请纠正我哪里做错了。 P.S:我已经将 View Controller 与故事板中的 segueIdentifier 正确连接,并将 VC 的类名更改为我的类。

【问题讨论】:

  • 记录了错误?例外?
  • 那么这里有什么问题呢?请添加有关您的问题的更多信息,因为现在几乎无法回答。
  • 您使用的是模态转场吗?如果没有,您肯定在故事板中有导航控制器
  • 检查您的转场标识符名称,它是否与转场名称匹配?也许您正在使用故事板视图控制器标识符名称进行 segue
  • 我也检查了我的 segue 名称。Control 即将进入下一个视图控制器 viewdidload 和 tableview 委托问题是它没有显示下一个视图控制器@suhit

标签: ios objective-c uinavigationcontroller storyboard push


【解决方案1】:

此代码对您使用 Storyboard ID 更改视图控制器非常有用。

例如 - 有 2 个视图控制器,分别命名为 FirstViewController 和 SecondViewController。 如果你想从 FirstViewController 移动到 SecondViewController,有一个使用 Storyboard ID 的简单代码。

第 1 步:-

输入两个 ViewController 的 StoryBoard ID

第 2 步:-

在FirstViewController中写代码——

let secondVC =  self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewController") as! SecondViewController

self.navigationController?.pushViewController(secondVC, animated: true)

【讨论】:

    【解决方案2】:

    您在 performSegueWithIdentifier 中的代码实际上什么都不做。因此,要显示目标场景,您必须将其连接到 Interface Builder 中,如下所示:

    • 在导航控制器中嵌入第一个场景(菜单:编辑器/嵌入/导航控制器)
    • 创建第二个场景
    • 在第一个场景上创建一个触发第二个场景的控件
    • 将控件从第一个场景连线(Ctrl-Drag)到第二个场景
    • 在“鼠标按钮向上”的弹出菜单中,从 segue 中选择“推”选项

    那么它应该看起来像这样并且应该可以工作:

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-26
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      相关资源
      最近更新 更多