用 UIPopOverController 替换 UITableView

发布于 2024-11-16 11:17:51 字数 357 浏览 4 评论 0原文

我有一个 UITableView,它不占据 iPad 的整个屏幕。我当前的视图是 UITableView 的数据源和委托。现在我想用 UIPopOverController 替换当前的 UITableView。从我在网上看到的示例来看,似乎大多数人都会创建一个新类来子类化 UITableView,并在 UIPopOverController 中呈现该实例。就我而言,由于我当前的 viewController 已经是数据源和委托,所以我的步骤需要是:

(1)创建一个新类,子类化 UITableViewController (2) 使该类成为数据源和委托 (3) 在我的 UITableView 所在的当前 viewController 中呈现此类的实例?

谢谢。

I have a UITableView that does not take up the whole screen of the iPad. The current view I have it in is the datasource and delegate for the UITableView. Now I want to replace the current UITableView with a UIPopOverController. From the examples I see online, it seems like most people create a new class that subclasses UITableView, and present that instance in the UIPopOverController. In my case, since my current viewController is the datasource and delegate already, would my steps need to be:

(1) create a new class, subclassing UITableViewController
(2) make this class the datasource and delegate
(3) present an instance of this class in the current viewController where my UITableView was?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2024-11-23 11:17:51

制作一个新的导航控制器,并将其与 rootView 作为表一起呈现

- (IBAction)seeFavorites{
NSLog(@"Favorites accessed");
if([self.popOverController isPopoverVisible])
{


    [self.popOverController dismissPopoverAnimated:YES];
    return;
}

UINavigationController *favNav = [[UINavigationController alloc]
                                  initWithRootViewController:favoritesView];


self.popOverController = [[[UIPopoverController alloc] 
                           initWithContentViewController:favNav] autorelease];


[popOverController presentPopoverFromBarButtonItem:revealFavorites permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
favoritesView.view.frame = CGRectMake(10, 10, 310, 320);

favoritesView.title = @"Favorites";

[favoritesView.tableView reloadData];


if (![self.popOverController isPopoverVisible]) {
    [favNav release];

}

}

以制作出口:

“File1”中

@class File2;
@interface FirstViewControlleriPad : UIViewController

{
//code
File2 *file2Outlet;

}
@property (nonatomic,retain) IBOutlet File2 *file2Outlet;
@end

在.m 文件中的

 #import "File2.h"
@implementation File1
@synthesize file2Outlet

appDelegate.h 中

#import "File1.h"
#import "File2.h"

@interface AppDelegate : NSObject  {
//...code for appDelegate
File1 *file1;
File2 *file2;
}
@property (nonatomic,retain) File1 *file1;
@property (nonatomic,retain) File2 *file2;
@end

的 appDelegate.m 中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

file1 = [[File1 alloc]init];
file2 = [[File2 alloc]init];
file1.file2Outlet = file2;
[file1 release];
[file2 release];

make a new navigation controller and present it with the rootView as the table

- (IBAction)seeFavorites{
NSLog(@"Favorites accessed");
if([self.popOverController isPopoverVisible])
{


    [self.popOverController dismissPopoverAnimated:YES];
    return;
}

UINavigationController *favNav = [[UINavigationController alloc]
                                  initWithRootViewController:favoritesView];


self.popOverController = [[[UIPopoverController alloc] 
                           initWithContentViewController:favNav] autorelease];


[popOverController presentPopoverFromBarButtonItem:revealFavorites permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
favoritesView.view.frame = CGRectMake(10, 10, 310, 320);

favoritesView.title = @"Favorites";

[favoritesView.tableView reloadData];


if (![self.popOverController isPopoverVisible]) {
    [favNav release];

}

}

to make an outlet:

in "File1"

@class File2;
@interface FirstViewControlleriPad : UIViewController

{
//code
File2 *file2Outlet;

}
@property (nonatomic,retain) IBOutlet File2 *file2Outlet;
@end

in the .m file

 #import "File2.h"
@implementation File1
@synthesize file2Outlet

in the appDelegate.h

#import "File1.h"
#import "File2.h"

@interface AppDelegate : NSObject  {
//...code for appDelegate
File1 *file1;
File2 *file2;
}
@property (nonatomic,retain) File1 *file1;
@property (nonatomic,retain) File2 *file2;
@end

in the appDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

file1 = [[File1 alloc]init];
file2 = [[File2 alloc]init];
file1.file2Outlet = file2;
[file1 release];
[file2 release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文