0

誰かが私に知らせてもらえますか:iphone sdkの単一のviewcontrollerで1つのビューから別のビューにナビゲートする方法は?単一のViewコントローラーで次のビューにプッシュして前のビューにポップしたいアプリケーションがあります。この機能をどのように実現できますか?前もって感謝します

4

4 に答える 4

2

セカンドビューを追加および削除できます。このようにナビゲートします

-(IBAction)navigate:(id)sender
{
  [self.view addSubView:secondView];
}

そしてこれは最初のビューにpoする

-(IBAction)popToFirstView:(id)sender
{
  [secondView removeFromSuperView];
}

注:- アニメーション効果を与えたい場合は、ビューの追加と削除にアニメーションを使用できます。

于 2013-01-31T11:33:33.200 に答える
1

プッシュとポップを取得するには、 UINavigation Controller を使用する必要があります。

このようにする

AppDelegate.hファイル

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
//this will be your first screen
@property (strong, nonatomic) FavViewController *favViewController;

@end

A* ppDelegate.m * ファイル内

#import "AppDelegate.h"
#import "FavViewController.h"


@implementation AppDelegate

@synthesize window = _window;
@synthesize favViewController;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

        //initialize view controller
        favViewController = [[FavViewController alloc] initWithNibName:@"FavViewController" bundle:nil];

       //add navigation controller
        UINavigationController *favouriteView = [[UINavigationController alloc] initWithRootViewController:favViewController];  


       //add controller to witndow
        self.window.rootViewController = favouriteView;   
        [self.window makeKeyAndVisible];    

        return YES;
    }

@end

ここで、新しいコントローラーにロード/プッシュするUIViewControllerに移動します

新しいコントローラーにロード/プッシュするには、このコードを使用します

//this will be next screen
DetailsViewController *detailsViewController = [[DetailsViewController alloc ]init];
[self.navigationController pushViewController:detailsViewController animated:YES];

戻るか、コントローラーをポップするには、これを使用します

//now it will send back to parent screen
[self.navigationController popViewControllerAnimated:YES]; 
于 2013-01-31T12:11:08.037 に答える
1

単一のView Controllerが必要な場合は、2つのビューを含むUIScrollViewと、ビューから別のビューにスクロールするボタンを使用してみてください...しかし、ヒントを与えることができれば、2つのView Controllerとナビゲーションを使用することをお勧めしますビューコントローラー

于 2013-01-31T11:34:05.180 に答える
0

私はこの問題の解決策を見つけました。これが以下の解決策です:-

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UIButton *backbtn;
    IBOutlet UIButton *nxtBtn;
    IBOutlet UILabel *label;
}
-(IBAction)nxt:(id)sender;
-(IBAction)ba:(id)sender;

@end

#import "ViewController.h"

@interface ViewController ()
@end

int count=0;

@implementation ViewController

- (void)viewDidLoad
{
    label.text=[[NSUserDefaults standardUserDefaults] objectForKey:@"NavigtionNumber"];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}
-(IBAction)nxt:(id)sender
{
    count++;
    label.text=[NSString stringWithFormat:@" navigation time %d",count];

    [[NSUserDefaults standardUserDefaults] setObject:label.text forKey:@"NavigtionNumber"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    ViewController *vc=[[ViewController alloc] init];

    [self.navigationController pushViewController:vc animated:YES];

}

-(IBAction)ba:(id)sender
{
    count--;
    label.text=[NSString stringWithFormat:@" navigation time %d",count];

    [[NSUserDefaults standardUserDefaults] setObject:label.text forKey:@"NavigtionNumber"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    [self.navigationController popViewControllerAnimated:YES];
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

これが将来他の人に役立つことを願っています。

ありがとう。

于 2013-01-31T11:58:40.693 に答える