开发者

Objective-C: How to send signal from view to view controller to change views?

I have a view controller that controls the switching between views. I would like one of the views to signal the view controller to switch to another view (and can't figure 开发者_运维知识库out how I can do this.)

To be more clear (hopefully): My view controller inserts a subview. That subview has a UITableView. I'd like, when you select a row in the UITableView, to remove the current subview and then switch to a different sub-view. Of course, I'd prefer the view controller to continue to keep track of which subview is loaded.

Does this make sense? (I'm still pretty green with Objective-C.)

Is there a way to send the view controller a message from the sub-view (that the view controller created)? Is there another way to accomplish this?

Thanks a bunch for the help... and I'd be happy to clarify if needed.


You might look into setting up a UINavigationController. Use the 2 UIViewControllers to control the individual views, and use the Navigation Controller to switch between the 2 views. From the UITableView, you can simply implement the method -

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Use this method to alloc the new view controller that you want to display

Then call the Navigation controller to push the new view controller onto the stack -

[self.navigationController pushViewController:controllerName animated:YES]

Finally, release the view controller that has disappeared.

This way the navigation controller keeps track of who is loaded, and can implement convenience functions like animating the transition. Also make sure to lookup the UITableViewController subclass - it is a subclass of UIViewController, but it provides some convenience functions for dealing with tables, like knowing when the user selects a particular row, and allows for the standard edit functions of most iOS apps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜