简体   繁体   English

使用xcode 4.2和情节提要通过代码更改视图?

[英]Change views via code using xcode 4.2 and storyboard?

How would I go about changing views via code using xcode 4.2 and storyboard? 我该如何使用xcode 4.2和情节提要通过代码更改视图? I'm trying to change views once a dynamic table view cell is clicked. 单击动态表格视图单元格后,我试图更改视图。 Since its dynamic I can't just link it with a segue... 由于它是动态的,所以我不能仅仅将它与一个segue链接起来。

I've tried changing using this code as suggested by another article on Stack Overflow but it doesn't work: 我已经尝试按照Stack Overflow上另一篇文章的建议使用此代码进行更改,但是它不起作用:

 UIViewController *alertView = [self.storyboard instantiateViewControllerWithIdentifier:@"alertView"];
[self.navigationController pushViewController:alertView animated:YES];

Here's a snippet of my code, hope it helps! 这是我的代码段,希望对您有所帮助!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==0){
     UIViewController *alertView = [self.storyboard instantiateViewControllerWithIdentifier:@"alertView"];
[self.navigationController pushViewController:alertView animated:YES];
    NSLog(@"This code is being called...");
}

In your storyboard create a segue from your UITableViewController to your alertView . 在情节alertView创建一个从UITableViewControlleralertView Make sure you do it by control dragging from the Controller (next to the First Responder icon) to your alertView rather than dragging from your table cell or something like that. 确保通过将控件从“控制器”(“第一响应者”图标旁边)拖动到alertView而不是从表格单元格之类的控件来做到这一点。 Choose a segue type of 'Push'. 选择“推”的segue类型。 Click on the segue's properties and make sure to give it an identifier like AlertViewSegue 单击segue的属性,并确保为其提供一个标识符,例如AlertViewSegue

Now you can programmatically invoke your segue with code like this: 现在,您可以使用以下代码以编程方式调用segue:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row==0){
        [self performSegueWithIdentifier:@"AlertViewSegue" sender:self];
    }
}

this is one of the better storyboard tutorials and it happens to use tableviews. 这是更好的情节提要教程之一,它恰好使用表视图。

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1 http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM