求助table view 大小如何更改,占据了webview 状态栏栏

09:49 提问
如何调整UITableViewController中的UITableView尺寸
在一组UITableViewController中的UITableView,想调整它的水平尺寸。已经试了好几种方法,但是都不太理想。
第一种方法:重写了-[UITableView setFrame:]但是标题部分没移动,而且两边还出现了黑色的空。(tableVIew已经是最底层了)
第二种方法:重写了-[UITableViewCell setFrame:],但是标题部分还是没移动,(这个必须移动)
第三种方法:调用UITableViewController中的- [self.view setFrame:],没实现。不知道该怎么办了,请大家帮忙。
按赞数排序
如果你调用- [UITableViewController viewDidAppear:]中的- [UITableView setFrame:],这样会有用:
- (void)viewDidAppear:(BOOL)animated
[self.tableView setFrame:CGRectMake(x, y, w, h)];
为了防止tableview两边出现黑条,设置背景颜色为白色:
[[[UIApplication sharedApplication] keyWindow] setBackgroundColor:[UIColor whiteColor]];
要调整标题的尺寸,我的代码如下:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
CGFloat headerHeight = 40;
UIView *headerView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, headerHeight)];
UILabel *cellLabel = [[UILabel alloc] initWithFrame: headerView.frame];
[cellLabel setText: @"My Text"];
[cellLabel setBackgroundColor: [UIColor clearColor]];
[headerView addSubview: cellLabel];
return headerV
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
return 40;
这段代码是取代这个方法:
`- (NSString *) tableView:(UITableView *)tableView `titleForHeaderInSection:`(NSInteger)section`
115关注|643收录
937关注|681收录
711关注|108收录
其他相似问题ios中怎么设置tableview的内缩进_百度知道21080人阅读
iPhone开发(350)
如果你准备将你的老的 iOS 6 app 迁移到 iOS 7 上,那么你必须注意了。当你的老的 app 在 iOS 7 设备上运行时,所有ViewController 的视图都整体上移了,因为 iOS 7 把整个屏幕高度(包括状态栏和导航栏)都作为了视图控制器的有效高度。于是你的视图上移了,并和上层的状态栏交叠在一起。你当然可以在 Xcode 中修改每个 View,将他们下移20个像素(状态栏高度)或者64个像素(状态栏+导航栏高度)。但是苹果显然已经考虑到这个问题,他们在 iOS 7 SDK 中为 ViewController 提供了一个 edgesForExtendedLayout 新属性。如果你将这个属性设置为UIRectEdgeNone,则 viewController 的所有子视图都会自动调整,这样在 iOS 7 下看到的效果和 iOS 6 完全一样。为了方便,你可以为 UIViewController 扩展一个子类,并覆盖它的 viewDidLoad 方法:@implementation DerivedViewController- (void)viewDidLoad{&&& [superviewDidLoad]; if ([selfrespondsToSelector:@selector(edgesForExtendedLayout)])&&&&&&&self.edgesForExtendedLayout = UIRectEdgeN}@end然后你以后所有的 ViewController 都从这个 DerivedViewController 类继承。但不幸的是,我们的程序仍然有大量 iOS&7 的用户 ,我们无法立即抛弃对 iOS 6 的支持。无论 edgesForExtendedLayout 还是UIRectEdgeNone,都只能在 iOS7 下有效。对于 iOS 6,我将以上代码修改为:- (void)viewDidLoad{&&& [superviewDidLoad];#if__IPHONE_OS_VERSION_MAX_ALLOWED &= 70000&&& if ([selfrespondsToSelector:@selector(edgesForExtendedLayout)])&&&&&&&self.edgesForExtendedLayout = UIRectEdgeN#else&&& float barHeight =0;&&& if (!isIPad()&& ![[UIApplication sharedApplication] isStatusBarHidden]) {&&&&&&&barHeight+=([[UIApplication sharedApplication]statusBarFrame]).size.&& &}&&& if(self.navigationController &&!self.navigationController.navigationBarHidden) {&&&&&&&barHeight+=self.navigationController.navigationBar.frame.size.&&& }&&& for (UIView *viewin self.view.subviews) {&&&&&&&&&&&&&&if ([view isKindOfClass:[UIScrollView class]]) {&&&&&&&&&&&view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y +barHeight, view.frame.size.width, view.frame.size.height - barHeight);&&&&&&& } else {&&&&&&&&&&&view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y +barHeight, view.frame.size.width, view.frame.size.height);&&&&&&&}&&& }#endif}通过宏 __IPHONE_OS_VERSION_MAX_ALLOWED 判断 deployment target 是否 &7.0。&7.0则使用新的 edgesForExtendedLayout API,负责使用比较笨的方法逐个下移 subviews,并自动根据状态栏/导航栏的可视状态计算要移动的偏移量。注:如果已升级至Xcode5,将导航控制器的 Top Bar 设置为一种“Opacque ...”(不透明)类型可解决此问题。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:3175072次
积分:31300
积分:31300
排名:第113名
原创:264篇
译文:154篇
评论:1425条
难度:高级
类型:技术教程
阅读:32663
阅读:49789
阅读:56065
阅读:77224
阅读:129652
(4)(7)(6)(4)(4)(5)(4)(4)(5)(4)(5)(5)(4)(4)(4)(4)(4)(4)(4)(4)(4)(4)(4)(5)(4)(5)(5)(6)(9)(5)(6)(4)(5)(5)(5)(5)(5)(4)(5)(5)(5)(6)(5)(3)(6)(5)(5)(6)(5)(6)(6)(3)(6)(8)(8)(5)(8)(8)(9)(4)(8)(10)(10)(10)(10)(11)(6)(4)(4)(8)(5)(5)(1)(3)(3)(1)(10)(2)(2)(1)(2)(2)一次 TableView 性能优化经历 - 推酷
一次 TableView 性能优化经历
作者:@__weak_Point 授权本站转载。
前段时间才换了工作,从面试准备到入职新公司,大概有半个多月时间吧,感慨颇深。找工作,太多运气成分在里面。有一些话想分享给大家:1.多认识一些这个行业的朋友,说不定你的下份工作就是其中的一个朋友介绍的。2.最好不要在7、8月份换工作,因为真的很热。
来到新公司后,一开始是熟悉项目、代码,以及改bug(填坑),然后上周开始做新的功能(准备挖坑)。生活不就是不停的挖坑和填坑吗?!遇到了一个Tableview卡帧的问题,花了点时间才解决,记录一下吧。好了,废话不多说,先上张效果图:
ps:其实是仿照nice的照片详情浏览效果
现在的照片详情页面是一个单独的页面(vc),用户想看其他的照片详情,需返回上一级页面,再点击进来,然后下个版本产品想改成上面那种效果。当时我想到两种方案:
一:用一个倾斜90&的tableview来做,简单,不用自己维护重用队列,每个cell放一个 vc 的view 就可以了,so easy。但是后面出现了问题,没记太清,当时也忘了截图,就换用第二种方案。
二:用scrollView来写,自己来维护重用队列,具体做法大家可以参考
。最后“完美”地实现了需求,开始做别的需求去了。
因为当时在模拟器上开发,也没想到真机上会卡帧。过了1天,这个功能提交给测试,然后就发现了问题:在scrollView滚动的时候,明显的感觉到了卡帧,然后就开始优化。
ps:有关TableView的效果一定要跑真机!!有关TableView的效果一定要跑真机!!有关TableView的效果一定要跑真机!! (重要的事说三遍)
因为也没有仔细看那个vc以及cell中的代码,就大概猜想了一下卡帧的原因:
1.尼玛,该不会是 UIScrollView的重用 没写好?
断点验证了下,vc只会创建3个,重用没问题呀。
2.因为涉及重用,所有vc里面tableview的内容肯定不是一下子全请求出来的,每滚动一次才会去请求下个页面的数据,以及初始化页面。然后再看nice,忽然发现它滚动的时候,状态栏居然没有网络请求的小菊花!!难不成是一次请求的?应该不会吧,这么多数据呀。为了验证这种猜想,用 Charles 拦截下,结果nice也是每滚动次发次请求的:
3.这个时候我又想到去搜nice的iOS工程师的github 和 博客,可惜github不能搜组织,就在微博搜了下
(互相关注 是后来事)
最后找到了他的博客,但是可惜没有找到我想要的。。。
不管什么原因,先跑下Instruments三件套吧(Time Profiler,Core Animation,GPU Driver)
好嘛,真是卡,一个一个看吧
1.首先排除了GPU的问题
这算多吗?我不太确定,对比 上面性能调优一文中的这段
得了,还是看那个vc里面是怎么写得吧??
- (void)refreshData
HBStoryDetailFetcher *fetcher = [[HBStoryDetailFetcher alloc] init];
fetcher.parameters = @{@&id&: _story_id};
[self runFetcher:fetcher forView:self.view success:^{
_story = [fetcher.story mutableCopy];
[self refreshCommentList];
} failure:^(NSError *error){
[self refreshCommentList];
- (void)refreshCommentList {
HBCommentListFetcher *fetcher = [[HBCommentListFetcher alloc] init];
fetcher.parameters = @{@&story_id&: _story_id};
[self runFetcher:fetcher forView:self.view success:^{
_page = 0;
_comments = [[NSMutableArray alloc] init];
[_comments ments];
[_tableView reloadData];
if (ments.count == 20) {
[self addLoadMore];
} failure:^(NSError *error){
[_tableView reloadData];
UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
HBStoryDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@&feedHomeCell& forIndexPath:indexPath];
cell.parent =
cell.isStoryDetailView = YES;
cell.indexPath = indexP
cell.story = _
cell.delegate =
[cell updateUI];
HBStoryCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:@&commentCell& forIndexPath:indexPath];
cell.parent =
cell.indexPath = indexP
cell.story = [_comments[indexPath.row-1] mutableCopy];
[cell updateUI];
UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return [HBStoryDetailCell calculateHeightForStory:_story] - [HBStoryDetailCell commentLabelHeight:_story];
return [HBStoryCommentCell calculateHeightForStory:_comments[indexPath.row-1]];
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 navigationview状态栏 的文章

 

随机推荐