如何点击uitableview分组 的HeaderInSection隐藏或展开自section

2155人阅读
自定义Section:修改UITableView的Section的背景和字体
第一次尝试修改UITableView的Section的背景和字体,头疼好一阵,终于找到了方法:
如同自定义Cell一样,使用UITableView的函数,可以自定义Section:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)
例子代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
&&& NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
&&& if (sectionTitle == nil) {
&&& // Create label with section title
&&& UILabel *label = [[[UILabel alloc] init] autorelease];
&&& label.frame = CGRectMake(12, 0, 300, 22);
&&& label.backgroundColor = [UIColor clearColor];
&&& label.textColor = [UIColor MujiLightTextColor];
&&& label.font = [UIFont fontWithName:@&Helvetica-Bold& size:14];
&&& label.text = sectionT
&&& // Create header view and add label as a subview
&& &UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
&& &[sectionView setBackgroundColor:[UIColor blackColor]];
&& &[sectionView addSubview:label];
&& &return sectionV
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:29581次
排名:千里之外
原创:15篇温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
iphone研发程序猿
LOFTER精选
阅读(787)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'UITableView自定义Section',
blogAbstract:'//自定义section的头部- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{&&& UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];//创建一个视图&&& UIImageView *headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 300, 30)];&&& UIImage *image = [UIImage imageNamed:@\"4-2.png\"];',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:4,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'iphone研发程序猿',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}An Error Was Encountered
The URI you submitted has disallowed characters.[ios]UITableView.RectForHeaderInSection 导致 rect 的部分无效的请求的异常,为什么?
我目前正在执行自定义标头 UITableView UITableView 类中已经可用之外 (以便我们可以有标题标题和副标题头一起漂浮在顶部)。
要这样做,我的表被分成许多部分可以是:
标题部分,是实际上一节空 UIView 作为一个标头 (因为我想要我自定义的标题,以浮于那空视图上方)。
或者它可以是一个副标题部分,是一个正常的部分,使用标头提供的 iOS (已经浮在顶部时我们滚动的一个)。
直到试试 2 自定义标头中这两种类型的截面可以完美地有行在他们和执行工程范围内。
当我尝试添加第二个自定义标头时,拿此异常时调用 UITableView.RectForHeaderInSection 方法:
NSInternalInconsistencyException: 请求的 rect 的部分无效 (6) 中的标头
问题是我的电话 this.UITableView.RectForHeaderInSection(6) 和弹出时异常 (确切的同一行中) 上,我能看到我的表有至少 7 节和因此,任何人都不应该无效的第 6 节。
我使用的 RectForHeaderInSection 把我浮头哪种应。
任何人都不会有的想法为什么它崩溃即使节不应该是无效?或越来越需要放我浮动的标头 (这将是我在标题部分中创建的空表视图页眉的帧) 的确切框架也许另一种方式吗?
只发现了可能涉及到我的问题,这个问题,但我觉得问题的根源是一样在这种情况下。
编辑:我意识到,当我说的节数应该是 7,它是 UITableViewSource 子类中的部分和不在表中的 '实际' 部分的数量。可能部分是删除或只是从未添加即使他们添加到源吗?如何可以看到我表 (不看我们有在源中的列表中的节数?
我将很可能发布我的代码的一部分明天,因为现在我意识到是没有足够的信息来查找可以这问题。
编辑 2:下面是代码看起来像:
// first we create the custom header (Title)
var title1 = new CustomHeader();
var section1 = this.Table.TableSource.AddSection();
section1.HeaderView = title1.V
// Fill section 1 with rows...
var section2 = this.Table.TableSource.AddSection();
// Fill section 2 with rows...
// We create the list of sections that our Title will contain
var title1Sections = new List&TableSection&();
title1Sections.Add(section1);
title1Sections.Add(section2);
// Now we call the method that will create our custom header
this.Table.TableSource.AddHeader(title1.View, title1Sections, this.Table.TableSource.Sections.IndexOf(section1);
所以这一点,我们有有漂浮的自定义标题标头在第 1 和第 2 条第 1 款。并已将浮动下标题表头,当他们撞到对方时的正常副标题头的 2 条。现在,AddHeader 方法:
public void AddHeader(UIView headerView, List&TableSection& sections, int indexOfFirstSection)
RectangleF rectForHeaderInTableView = this.TableView.RectForHeaderInSection(indexOfFirstSection); /* CRASHES HERE */
// Code that uses rectForHeaderInTableView to make our custom header float over everything...
如果我只有这样一个自定义标头,这款应用程序运行正常,有没有崩溃。但如果添加了更多节 (说允许各 3-4 节) 我在这里做的相同的方式和时它会尝试添加第二个自定义标头,添加自定义标头,该应用程序将会崩溃时想要 rectForHeaderInSection。如果我决定不具有自定义标头的第 1-2 节,而有一个 3-4,它仍然起作用。只要我只能有一个自定义标头,这款应用程序不会崩溃。
解决方法 1:
你说得对,"可能部分是删除或只是从未添加即使他们添加到源吗?"。他们不被添加的表。
您必须调用:
ReloadData()
对您要同步与为了防止部分无效索引的表中的数据源的连接。UITableView的section顶端粘滞效果是怎么实现的_百度知道
UITableView的section顶端粘滞效果是怎么实现的
提问者采纳
呃~这个是默认的。只要初始化tableview为UITableviewStylePlain还有定义section的headerview有两种方法:1、tableview.tableHeaderView
2、- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section第一种方法,header的会跟着tableview滚动隐藏,而第二种方法则有你说的那种粘滞效果。footer一样。
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁

我要回帖

更多关于 uitableview分组 的文章

 

随机推荐