![](/img/trans.png)
[英]How to implement common tap Gesture which will work for all View controllers
[英]How to create common UITableView for all view controllers?
有谁知道如何在多个ViewControllers
使用单个UITableView
吗?
我需要为所有视图控制器创建一个通用的UITableView
,并在整个应用程序中使用它。
任何帮助表示赞赏。
使用ContainerView ,您可以将ContainerView拖到情节提要中的ViewController中,并根据需要调整大小。 您可以在所有需要TableView的 ViewController中使用ContainerView 。
附件是我的一个正在使用ContainerView的应用程序的屏幕快照,该应用程序在ViewController中包含TableView 。 我在2个不同的ViewControllers中使用相同的东西。
您可以使用单例。 这是一个例子:
CommonTableView.h文件:
#import <Foundation/Foundation.h>
@interface CommonTableView : UITableView <UITableViewDelegate>
+ (CommonTableView *)sharedInstance;
@end
CommonTableView.m文件:
#import “CommonTableView.h”
CommonTableView *sharedInstance = nil;
@implementation CommonTableView
+ (CommonTableView *)sharedInstance
{
static dispatch_once_t pred;
dispatch_once(&pred, ^{
sharedInstance = [[super allocWithZone:nil] init];
});
return sharedInstance;
}
- (id)init
{
self = [super init];
if (self) {
self.delegate = self;
//customize your table view
}
return self;
}
#pargma mark - UITableView delegate
//…
@end
然后,您可以使用所需的UIViewControllers中的[CommonTableView sharedInstance]访问tableView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.