Iphone 基于页面的应用程序与uitableview;当转到下一页时,如何显示详细视图并在表中显示其他数据?

Iphone 基于页面的应用程序与uitableview;当转到下一页时,如何显示详细视图并在表中显示其他数据?,iphone,ios,uitableview,uipageviewcontroller,Iphone,Ios,Uitableview,Uipageviewcontroller,我有一个基于页面的应用程序。在每一页的顶部有3个UIButton,右边是带字母表的uiscrollview(uibuttons用于在uitable中对数据进行排序),中间是uitableview。如何显示单元格的详细视图?如果有必要添加uinavigationcontroller,我不能这样做。如果我添加它,它将禁用与我的表、按钮和滚动视图的交互。 另一个问题是,当转到下一页时,如何在tableview和scrollview中显示新数据 我有rootViewController类和DataVie

我有一个基于页面的应用程序。在每一页的顶部有3个UIButton,右边是带字母表的uiscrollview(uibuttons用于在uitable中对数据进行排序),中间是uitableview。如何显示单元格的详细视图?如果有必要添加uinavigationcontroller,我不能这样做。如果我添加它,它将禁用与我的表、按钮和滚动视图的交互。 另一个问题是,当转到下一页时,如何在tableview和scrollview中显示新数据

我有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];
    }
}
}

经过几次操作,它的工作,但我需要帮助,使其工作良好

所以现在看起来像这样

下一个问题:如何删除顶部的棕色空间


::更新::


问题解决了。只需将UINavigationController的y轴位置设置为-20;)

可能还有其他方法,但到目前为止最简单的方法是使用导航控制器。事实上,它就是为了做到这一点而建造的

如果不需要导航栏,则可以将其隐藏在ViewWillDisplay函数中

[self.navigationController setNavigationBarHidden:YES animated:YES];
然后,您可以添加其他UIViewController,以便在用户选择单元格时推送

再次阅读您的OP后,我不确定您是如何添加navigationController的

要使用navigationController,请创建它并在开始时加载它。然后创建当前的viewController(带有按钮和表格等的viewController),并将其设置为navigationController的rootViewController

然后显示navigationController

您能否解释一下如何添加navigationController,因为它可能有助于了解出现了什么问题

谢谢

::编辑::

好的,我的假设是正确的

您使用导航控制器的方式与预期不同

好的,现在您的AppDelegate文件将有一个方法应用程序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;
}
你应该把它改成这样

- (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函数
视图中将显示动画
添加行

[self.navigationController setNavigationBarHidden:YES animated:animated];
这将隐藏视图顶部的导航栏,以便您仍然可以访问按钮

您需要一个新的ViewController和xib文件(例如DetailViewController)

当用户选择一个表行时,您需要执行如下操作

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

//pass in details of which row was selected.

[self.navigationController pushViewController:detailView animated:YES];
然后将显示新视图和新viewController。您还需要编写一种传入数据的方法(在DetailViewController上设置属性)


希望这有帮助。

我不确定这个关于创建基于导航的项目的链接是否对您有帮助。。(http://iosmadesimple.blogspot.com/2012/08/navigation-based-project-doing-it.html)

在该教程中,有一个名为SampleViewController的类,它是UIViewController的子类。您可能希望将tableView放入SampleViewController.xib文件中。然后在SampleViewController.h文件中,添加一个IBMOutlet UITableView*yourTable属性并合成它。将其连接到.xib文件中的tableView//或者你也可以通过编程来实现

在SampleViewController.h中,使您的接口头如下所示。。我想你已经知道了

@接口示例ViewController:UIViewController

在SampleViewcontroller.m中的viewDidLoad方法下,将表委托和数据源设置为self:

yourTableView.delegate = self;
yourTableView.datasource = self;
之后,实现tableView委托和数据源方法//您已经知道这些,因为您已经能够显示tableview;)

其中一种方法是“tableview:DidSelectatinIndexPath:”-->这是单击其中一个单元格时可以放置代码的部分。

假设您有DetailsViewController类,这是您希望在单击单元格并显示其详细信息后显示的类

DetailsViewController类必须具有一个变量,该变量将接受要显示的数据。比如说,一条NSString*detailsMessage//做@property和@synthesis的事情

让我们回到SampleViewController.m文件,在tableview:DidSelectatinIndexPath:Method: 在这个方法里面。。把这些代码放进去

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

我希望这有帮助(

谢谢!我知道如何创建uitable,设置委托并调用方法DidSelectRowatinexPath。我还知道如何使用uinavigationcontroller。但我不知道如何将它添加到基于pagecontroller的项目中:(((哦,我不好..很抱歉,我帮不了什么忙。)(方法didFinishLaunchingWithOptions为空。所有控制器都在rootVievController.m中创建。我想我必须更改此类以获得nedeed结果。好的,在构建设置中,您将有一个类似于主界面的选项。删除该选项中的任何内容,并按上述方式编写AppDelegate方法。使用RootViewController就地f MainViewController。基本上,您需要将您的RootViewController设置为navigationController的RootViewController。如果我这样做,我的功能将丢失。我不知道如何使用翻转制作页面。在生成设置中,没有主界面或类似界面。