简体   繁体   中英

How to load a UIView from a tap?

I'm new to iPhone Development and I did some examples and seen code and code and more code but I still can't get the

when the user taps here show this view using this animation, and go back after (user taps a back button)

I did some Tab Bar examples, Utility examples, etc but when I start a project from scratch the code never does what I want :-/

every time I create a View (xib) I also create the controller (h and m files), as all examples are like this, and I have no idea if I can only create 4 Views and just have one controller :-(

when a user taps a UITableCell how can I load a new view using an animation ? and how can I go back to the UITableCell the user was?

kind'a (in C#)

myNewForm f = new myNewForm();
f.show();

...

this.Close();

If someone can share some knowledge or a tutorial or a screencast, I will greatly appreciate

Thank you!

Tap a cell and show a new view, if your table view has a UINavigationBar:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == myRow) {
        MyViewController *vc = [[MyViewController alloc] init];
        [self.navigationController pushViewController:uvc animated:YES];
        [vc release];
    }
}

Then the user can tap back as well. You can present modally as well, but would need to implement a way to return to the table view, by using:

[self presentModalViewController:vc animated:YES];

But the simplest base case is this, which you can see used in any template app's AppDelegate:

[window addSubview:vc.view];

Remember that the OS is doing a lot for you, including teaching you about MVC by encouraging the creating of controller classes.

You want to read about UINavigationController . Maybe also read the "View Programming Guide for iPhone OS", all available at http://developer.apple.com .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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