简体   繁体   English

iPhone - 按下按钮加载新的 UIView

[英]iPhone - Load a new UIView on pressing button

say I have a UITableView and upon selecting a new table row (thus firing the delegate method), I want to load a new UIView (which I have created in storyboard) and pass to it a data item.假设我有一个 UITableView 并在选择一个新的表行(从而触发委托方法)后,我想加载一个新的 UIView(我在情节提要中创建的)并将一个数据项传递给它。

Obviously the new UIView is added as a UIViewController in storyboard and has its own controller class..显然新的 UIView 在 storyboard 中添加为 UIViewController 并且有自己的 controller class..

How would I go about doing that?我将如何 go 这样做?

Thank you!谢谢!

Try something along the lines of this:尝试类似的方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:dvController animated:YES];
}

If you are using storyboards and not XIB files, use this code...如果您使用的是故事板而不是 XIB 文件,请使用此代码...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DetailViewController *dvController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

    [self.navigationController pushViewController:dvController animated:YES];
}

Also you need to set the "Identifier" field in Interface Builder to the name used in self.storyboard instantiateViewControllerWithIdentifier:您还需要将 Interface Builder 中的“Identifier”字段设置为self.storyboard instantiateViewControllerWithIdentifier:

Cheers!干杯!

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

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