我在我的应用程序上使用选项卡栏 (UITabBarController),我希望自定义单击“更多”按钮时出现的表格的外观。
我已经研究出如何通过设置来更改更多屏幕上导航栏的外观
self.moreNavigationController.navigationBar.barStyle
在 UITabBarController 的子类中,我设法通过修改来更改表格的背景颜色
self.moreNavigationController.topViewController.view.backgroundColor
,但我无法弄清楚如何更改表格上显示的单元格中的字体颜色。
我希望我能用
self.moreNavigationController.topViewController.view.visibleCells
但这似乎总是空的。我尝试在 viewDidLoad、viewWillAppear 和 viewDidAppear 中执行此操作,但没有成功。对象 self.moreNavigationController.topViewController 的类型为 UIMoreListController,它似乎没有记录,我在界面中看不到任何对我有帮助的明显内容。
有任何想法吗?
根据 Stephan 的建议,替换 moreNavigationController 的数据源,这里是我实现的代码的快速概览。
我创建了一个名为 MoreTableViewDataSource 的新类,它实现了 UITableViewDataSource 协议。更多页面实际用于构建表的控制器称为 UIMoreListControllerModern,它仅实现 UITableViewDataSource 协议所需的部分。我的实现看起来像这样。
-(MoreTableViewDataSource *) initWithDataSource:(id<UITableViewDataSource>) dataSource
{
self = [super init];
if (self)
{
self.originalDataSource = dataSource;
}
return self;
}
- (void)dealloc
{
self.originalDataSource = nil;
[super dealloc];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return [originalDataSource tableView:table numberOfRowsInSection:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [originalDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
cell.textColor = [UIColor whiteColor];
return cell;
}
然后在我的 CustomTabBarController 类中我重写 viewDidLoad ,如下所示:
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *moreController = self.moreNavigationController;
moreController.navigationBar.barStyle = UIBarStyleBlackOpaque;
if ([moreController.topViewController.view isKindOfClass:[UITableView class]])
{
UITableView *view = (UITableView *)moreController.topViewController.view;
view.backgroundColor = [UIColor blackColor];
moreTableViewDataSource = [[MoreTableViewDataSource alloc] initWithDataSource:view.dataSource];
view.dataSource = moreTableViewDataSource;
}
}
根据要求这里是头文件
@interface MoreTableViewDataSource : NSObject <UITableViewDataSource>
{
id<UITableViewDataSource> originalDataSource;
}
@property (retain) id<UITableViewDataSource> originalDataSource;
-(MoreTableViewDataSource *) initWithDataSource:(id<UITableViewDataSource>) dataSource;
@end
and
#import "MoreTableViewDataSource.h"
@interface CustomTabBarController : UITabBarController
{
MoreTableViewDataSource *moreTableViewDataSource;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)