1

ページベースのアプリがあります。各ページの上部に 3 つの uibutton、右側にアルファベット付きの uiscrollview (uitable でデータを並べ替えるための uibutton)、中央に uitableview があります。セルの詳細ビューを表示するには? uinavigationcontroller を追加する必要がある場合、これはできません。追加すると、テーブル、ボタン、スクロールビューとのやり取りが無効になります。そして別の質問は、次のページに移動したときにテーブルビューとスクロールビューに新しいデータを表示する方法です??

rootViewController クラスと DataViewController クラスがあります。rootViewController リスト:

@interface RootViewController ()
@property (readonly, strong, nonatomic) ModelController *modelController;
@end

@implementation RootViewController

@synthesize pageViewController = _pageViewController;
@synthesize modelController = _modelController;
@synthesize navContr = _navContr;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.

//[self presentModalViewController:navContr animated:YES];

self.pageViewController = [[[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil] autorelease];
self.pageViewController.delegate = self;

DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = [NSArray arrayWithObject:startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];

   self.pageViewController.dataSource = self.modelController;

[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];

self.navContr = [[UINavigationController alloc] initWithRootViewController:self.pageViewController];
[self.view addSubview:self.navContr.view];


// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
self.pageViewController.view.frame = pageViewRect;

[self.pageViewController didMoveToParentViewController:self];

// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
for (UIGestureRecognizer *recognizer in self.pageViewController.gestureRecognizers){
    if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]){
        [recognizer setEnabled:NO];
    }
}
}

いくつかの操作の後、動作しますが、うまく動作させるには助けが必要です!

だから今はこんな感じ

1 2

次の質問: 上部の茶色のスペースを削除するにはどうすればよいですか?


::アップデート::

問題が解決しました。UINavigationController の y 軸位置を -20 に設定するだけです;)

4

2 に答える 2

0

ナビゲーションベースのプロジェクトの作成に関するこのリンクが役立つかどうかはわかりません.. (http://iosmadesimple.blogspot.com/2012/08/navigation-based-project-doing-it.html)

そのチュートリアルから、UIViewController のサブクラスである SampleViewController というクラスがあります。tableView を SampleViewController.xib ファイルに入れたいと思うかもしれません。次に、SampleViewController.h ファイルで、IBOutlet UITableView* yourTable プロパティを追加して合成します。.xib ファイルの tableView に接続します。//または、プログラムで実行することもできます

SampleViewController.h で、インターフェイス ヘッダーを次のようにします。これは既にご存知だと思います...

@interface SampleViewController:UIViewController < UITableviewDelegate, UITableViewDatasource >

SampleViewcontroller.m の viewDidLoad メソッドの下で、テーブル デリゲートとデータソースを self に設定します。

yourTableView.delegate = self;
yourTableView.datasource = self;

その後、tableView のデリゲート メソッドとデータソース メソッドを実装します... //すでにテーブルビューを表示できたので、それらはすでにわかっています ;)

これらのメソッドの 1 つは "tableview:didSelectAtIndexpath:" です --> これは、セルの 1 つをクリックしたときにコードを配置できる部分です。

DetailsViewController クラスがあるとします。これは、セルをクリックしてその詳細を表示した後に表示するクラスです。

DetailsViewController クラスには、表示したいデータを受け入れる変数が必要です。たとえば、NSString *detailsMessage; としましょう。// @property と @synthesize を実行...

SampleViewController.m ファイルに戻りましょう。tableview:didSelectAtIndexpath: Method: の下にあり、そのメソッド内に..これらのコードを配置します。

DetailsViewController *detailsVC = [[DetailsViewController alloc] init];
detailsVC.detailsMessage = @"The Data you want to pass.";
[self.navigationController pushViewController:detailsVC animated:YES];

これが役立つことを願っています。:(

于 2012-09-24T13:04:29.127 に答える
0

他の方法もあるかもしれませんが、最も簡単な方法は、ナビゲーション コントローラーを使用することです。実際、まさにこれを行うために構築されています。

navigationBar が必要ない場合は、viewWillAppear 関数で非表示にすることができます。

[self.navigationController setNavigationBarHidden:YES animated:YES];

次に、ユーザーがセルを選択したときにプッシュする他の UIViewController を追加できます。

OPをもう一度読んだので、navigationControllerをどのように追加しているのかわかりません。

navigationController を使用するには、それを作成し、開始時にロードします。次に、現在のviewController(ボタンやテーブルなどを含むもの)を作成し、これをnavigationControllerのrootViewControllerとして設定します。

次に、navigationController を表示します。

何が問題なのかを理解するのに役立つかもしれないので、navigationController を追加する方法を説明していただけますか。

ありがとう

::編集::

OK、私の仮定は正しかった。

ナビゲーション コントローラーの使用方法は、意図された方法ではありません。

わかりましたので、現時点では、AppDelegate ファイルにはメソッド Application didFinishLaunching... があります。

それはこのようなものになります...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[OJFViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

このように変更する必要があります...

最初にAppDelegateにプロパティを追加します...

@property (nonatomic, strong) UINavigationController *navigationController;

次に、didFinishLaunchingMethod をこれに変更します...

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[OJFViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

これにより、MainViewControllerが表示されますが、NavigationController内に含まれるようになりました。

次に MainViewController 関数に次viewWillAppearAnimatedの行を追加します...

[self.navigationController setNavigationBarHidden:YES animated:animated];

これにより、ビューの上部にある navigationBar が非表示になるため、引き続きボタンにアクセスできます。

新しい ViewController と xib ファイル (DetailViewController など) が必要です。

When the user selects a table row you need to then do something like...

DetailViewController *detailView = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

//pass in details of which row was selected.

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

これにより、新しいビューと新しい viewController が表示されます。また、データを渡す方法を記述する必要があります (DetailViewController でプロパティを設定します)。

お役に立てれば。

于 2012-09-24T11:59:41.580 に答える