[英]IOS7: UITabBarController's “more” tab design is is disturbed
我在項目的storyboard
UITabBarController
中使用UITabBarController
。 該項目已經使用iOS6
SDK進行了編碼。 現在,我正在研究其iOS7
兼容性。 我通過提供自己的datasource
定制“ more
”選項卡的表tableview
的設計,並且它在iOS6
完美地工作。 在iOS7
,奇怪的是設計受到干擾。 請查看以下圖片以獲取更多說明。
iOS6:
IOS 7:
最后是代碼:-
-(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
與其在單元格中創建自己的titleLbl
實例,不如簡單地以相同的方式定位和設置現有titleLabel
的樣式? 我不確定為什么會這樣,因為您尚未上傳MoreTabCell
的代碼,但是您可以嘗試設置titleLabel.text = nil;
如果您不想停止使用titleLbl
。
自己嘗試之后,我發現訣竅是將表視圖的委托設置為自定義的一個或nil
。 由於UIMoreListController
在tableView:willDisplayCell:forRowAtIndexPath:
方法中填寫了標題和其他內容。
希望這會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.