我在我的项目中使用UITabBarController
的storyboard
。该项目已经编码为iOS6
sdk。现在我正在研究其兼容性iOS7
。我已经通过提供我自己的datasource
来定制“more
”标签的tableview
的设计,并且它在iOS6
中完美地工作。奇怪地在iOS7
设计被打扰。 Plz看到下面的图像更详细阐述。IOS7:UITabBarController的“更多”选项卡设计受到干扰
iOS6的:
iOS7:
最后这里是代码: -
-(void)tabBarController:(UITabBarController *)tbController didSelectViewController:(UIViewController *)viewController {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navCtr=(UINavigationController *)viewController;
UITableView *moreTable = (UITableView *)tabBarController.moreNavigationController.topViewController.view;
moreTable.dataSource = nil;
if ([[navCtr.viewControllers lastObject] isKindOfClass:NSClassFromString(@"UIMoreListController")]){
moreTableViewDataSource=[[MoreTableViewDataSource alloc] init];
moreTable.dataSource = moreTableViewDataSource;
[moreTable setBackgroundColor:[UIColor clearColor]];
[moreTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
}
MoreTableViewDataSource.h
@interface MoreTableViewDataSource : NSObject <UITableViewDataSource,UITableViewDelegate>
{
}
@property (strong, nonatomic) id<UITableViewDataSource> originalDataSource;
-(MoreTableViewDataSource *) initWithDataSource:(id<UITableViewDataSource>) dataSource;
@end
MoreTableViewDataSource.m
@implementation MoreTableViewDataSource
-(MoreTableViewDataSource *) initWithDataSource:(id<UITableViewDataSource>) dataSource
{
self = [super init];
if (self)
{
self.originalDataSource = dataSource;
}
return self;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 48.0;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MoreTabCell *cell = (MoreTabCell*)[tableView dequeueReusableCellWithIdentifier:@"MoreTabCell"];
if (cell==nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"MoreTabCell" owner:nil options:nil] objectAtIndex:0];
}
switch (indexPath.row) {
case 0:
cell.titleLbl.text=NSLocalizedString(@"approach", nil);
break;
case 1:
cell.titleLbl.text=NSLocalizedString(@"opening_time", nil);
break;
case 2:
cell.titleLbl.text=NSLocalizedString(@"weather", nil);
break;
case 3:
cell.titleLbl.text=NSLocalizedString(@"ticket", nil);
break;
case 4:
cell.titleLbl.text=NSLocalizedString(@"contact", nil);
break;
default:
break;
}
cell.titleLbl.textColor=[UIColor lightBlueColor];
[cell.titleLbl setFont:[UIFont setGothicFontBoldWithSize:14.0]];
[cell.imgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"moreIcon%d",indexPath.row+1]]];
cell.accessoryView = nil;
return cell;
}
@end
你是对的。尽管通过设置委托零你失去了tabbarcontroller的自动选择,但一个自定义的委托会做。非常感谢。 –