怎么才能把UITableViewCell设为设置文字不可选中中

UITableView设置为静态的单元格。 是否有可能隐藏的cell编程?
我的图书馆
UITableView设置为静态的单元格。 是否有可能隐藏的cell编程?
1.&您正在寻找这样的解决方案: StaticDataTableViewController 2.0 它可以显示/隐藏/重装任何静态的单元格带或不带动画![self cell:self.outletToMyStaticCell1 setHidden:hide];
[self cell:self.outletToMyStaticCell2 setHidden:hide];
[self reloadDataAnimated:YES];
注意只(reloadDataAnimated:是/否) (不调用[self.tableView reloadData]直接)&2.&我的解决方案进入了类似的方向,加雷,虽然我做不同的事情。 这里有云: 1。隐藏的单元格 有没有办法直接隐藏的单元格。UITableViewController是数据源,它提供了静态的cell,目前没有任何方法来告诉它“不提供小区x”。 因此,我们必须为我们自己的数据源,它委托给UITableViewController为了得到静cell。 最简单的是子类UITableViewController和override这就需要隐藏单元格时不同的行为。 在最简单的情况下(单节表 CodeGo.net,所有的cell都有高度),这将是这样的:- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
return [super tableView:tableView numberOfRowsInSection:section] - numberOfCellsH
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
// Recalculate indexPath based on hidden cells
indexPath = [self offsetIndexPath:indexPath];
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
- (NSIndexPath*)offsetIndexPath:(NSIndexPath*)indexPath
int offsetSection = indexPath. // Also offset section if you intend to hide whole sections
int numberOfCellsHiddenAbove = ... // Calculate how many cells are hidden above the given indexPath.row
int offsetRow = indexPath.row + numberOfCellsHiddenA
return [NSIndexPathindexPathForRow:offsetRow inSection:offsetSection];
如果你的表中有多个部分,或cell有不同的高度,你需要重写的原则也适用于这里:你需要抵消indexPath,部分和行委托给超之前。 也请记住,像indexPathdidSelectRowAtIndexPath:将不同的cell,这取决于状态(即,cell中隐藏的数目)。因此,它可能是一个好主意,总是抵消任何indexPath,并与这些值的工作。 2。动画的变化 由于加雷思已经说过的,你会得到大的毛刺,如果你的动画reloadSections:withRowAnimation:方法。 我发现,如果你调用reloadData:事后,动画大为改善(左只有轻微的毛刺)。该表的动画后正确显示。 那么,我做的是:- (void)changeState
// Change state so cells are hidden/unhidden
// Reload all sections
NSIndexSet* reloadSet = [NSIndexSetindexSetWithIndexesInRange:NSMakeRange(0, [self numberOfSectionsInTableView:tableView])];
[tableView reloadSections:reloadSet withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView reloadData];
3.&我了,其实隐藏的部分,并且不删除它们的替代。我试过@henning77的做法,但我一直运行到问题时,我改变了静态的UITableView的节数。已经工作得很好,但我主要是想隐瞒的部分,而不是行。我在飞行中删除行,但它是一个,所以我一直在努力,集团的事情,到我需要显示或隐藏部分。下面是我如何隐藏部分的示例: 首先,我声明一个NSMutableArray里物业@property (nonatomic, strong) NSMutableArray *hiddenS
在viewDidLoad中(或您查询您的数据后),你可以添加你想要隐藏的数组部分。- (void)viewDidLoad
hiddenSections = [NSMutableArray new];
if(some piece of data is empty){
// Add index of section that should be hidden
[self.hiddenSections addObject:[NSNumber numberWithInt:1]];
... add as many sections to the array as needed
[self.tableView reloadData];
那么下面的实现代码如下- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
if([self.hiddenSections containsObject:[NSNumber numberWithInt:section]]){
return [super tableView:tableView titleForHeaderInSection:section];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
if([self.hiddenSections containsObject:[NSNumber numberWithInt:indexPath.section]]){
return [super tableView:tableView heightForRowAtIndexPath:[self offsetIndexPath:indexPath]];
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
if([self.hiddenSections containsObject:[NSNumber numberWithInt:indexPath.section]]){
[cell setHidden:YES];
然后设置页眉和页脚高度为1隐藏部分,您不能设置高度为0。这额外的2像素的空间,但我们可以弥补它的下一个可见标题的高度。-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
CGFloat height = [super tableView:tableView heightForHeaderInSection:section];
if([self.hiddenSections containsObject:[NSNumber numberWithInt:section]]){
height = 1; // Can't be zero
else if([self tableView:tableView titleForHeaderInSection:section] == nil){ // Only adjust if title is nil
// Adjust height for previous hidden sections
CGFloat adjust = 0;
for(int i = (section - 1); i &= 0; i--){
if([self.hiddenSections containsObject:[NSNumber numberWithInt:i]]){
adjust = adjust + 2;
if(adjust & 0)
if(height == -1){
height = self.tableView.sectionHeaderH
height = height -
if(height & 1){
height = 1;
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
if([self.hiddenSections containsObject:[NSNumber numberWithInt:section]]){
return [super tableView:tableView heightForFooterInSection:section];
然后,如果你有特定的行隐藏您可以在numberOfRowsInSection且行中的cellForRowAtIndexPath返回。在这个例子中我在这里有一节有三排,其中任意三个可能是空的,需要被删除。- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
NSInteger rows = [super tableView:tableView numberOfRowsInSection:section];
if(self.organization != nil){
if(section == 5){ // Contact
if([self.organization objectForKey:@"Phone"] == [NSNull null]){
if([self.organization objectForKey:@"Email"] == [NSNull null]){
if([self.organization objectForKey:@"City"] == [NSNull null]){
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
return [super tableView:tableView cellForRowAtIndexPath:[self offsetIndexPath:indexPath]];
使用此offsetIndexPath计算indexPath的行你在哪里有条件删除行。没有必要的,如果你只是躲在节- (NSIndexPath *)offsetIndexPath:(NSIndexPath*)indexPath
int row = indexPath.
if(self.organization != nil){
if(indexPath.section == 5){
// Adjust row to return based on which rows before are hidden
if(indexPath.row == 0 && [self.organization objectForKey:@"Phone"] == [NSNull null] && [self.organization objectForKey:@"Email"] != [NSNull null]){
else if(indexPath.row == 0 && [self.organization objectForKey:@"Phone"] == [NSNull null] && [self.organization objectForKey:@"Address"] != [NSNull null]){
row = row + 2;
else if(indexPath.row == 1 && [self.organization objectForKey:@"Phone"] != [NSNull null] && [self.organization objectForKey:@"Email"] == [NSNull null]){
else if(indexPath.row == 1 && [self.organization objectForKey:@"Phone"] == [NSNull null] && [self.organization objectForKey:@"Email"] != [NSNull null]){
NSIndexPath *offsetPath = [NSIndexPath indexPathForRow:row inSection:indexPath.section];
return offsetP
有很多覆盖,但我喜欢这种方法,它是安装程序的hiddenSections数组,添加到它,它会隐藏在正确的部分。隐藏的行也有点trouble,但有可能。我们不能只设置我们想要隐藏为0,如果我们'一个分组的UITableView的边框将不会得到正确绘制行的高度。&4.&是的,这是绝对有可能的,虽然我的问题在挣扎,我设法让cell隐藏,一切工作不错,但我目前还不能做出的东西整齐地制作动画。以下是我发现: 我躲在基于对一个ON / OFF开关的优先部分的优先行中的状态行。如果开关处于ON有1排在它下面的部分,否则有2个不同的行。 我有一个叫当开关切换选择器,我设置一个变量来表示我的状态。然后我打电话:[[self tableView] reloadData];
我重写的实现代码如下:willDisplayCell:forRowAtIndexPath:函数,如果电池是应该被隐藏我这样做:[cell setHidden:YES];
隐藏的单元格,其内容,但不删除它占用的空间。 要删除空间,覆盖实现代码如下:heightForRowAtIndexPath:函数,返回0,表示不应该被隐藏的行。 您还需要重写实现代码如下:numberOfRowsInSection:与返回行的那部分数量。你所要做的奇怪在这里,所以,如果你的表是一个combinations的样式出现在正确的cell圆角。在我的静态表有整套cell的部分,所以包含该选项的优先个单元格,然后1cell为ON状态和2个以上的cell为OFF状态的选项,一共有4个cell。当选项为ON时,我不得不返回4,这包括隐藏的选项,使得所显示的最后一个选项有一个圆形的盒子。当选项是关闭的,不显示最后两个选项,所以我返回2。这一切都感觉沉闷。很抱歉,如果这不是很清楚,它的棘手来形容。只是到安装,这是在IB表款的建设: 行0:选项有ON / OFF开关 第1行:当选项为ON时显示 第2行:当选项为OFF显示 第3行:当选项为OFF显示 所以当选项设置为ON的表报告两行分别是: 行0:选项有ON / OFF开关 第1行:当选项为ON时显示 如果选项是关闭的表报告四行分别是: 行0:选项有ON / OFF开关 第1行:当选项为ON时显示 第2行:当选项为OFF显示 第3行:当选项为OFF显示 这种方法并不觉得正确的有以下几个原因,它只是据我已经得到了我那么远,那么请知道如果你找到一个更好的办法。我观察到的问题,到目前为止有: 这感觉不对被告诉该表的行数是不同的东西大概是包含在基础数据中。 我似乎无法以动画的变化。我已经实现代码如下:reloadSections:withRowAnimation:不是reloadData,结果似乎并没有什么意义,我仍然试图得到这个工作。目前什么似乎是发生了的tableView不更新正确的行这么一保持隐藏状态,应该在优先行下显示和空隙离开了。我认为这可能与有关基础数据的优先点。 希望将能够建议或者如何与动画延长,但也许这将让你开始。我的道歉缺乏超链接的函数,我把他们但他们的垃圾邮件过滤器被拒绝了我是一个相当&5.&我一直在争吵与UITableView的几个小时。如果你不关心的动画,只是想隐藏静态cell,这个工作- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
UITableViewCell* cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
if(cell == cellYouWantToHide)
return 0; //set the hidden cell's height to 0
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
请记住,你躲在需要有ClipToBounds=YEScell。否则,该文本将堆积在UITableView中。&6.&我发现在静态表动画躲在cell的溶液。// Class for wrapping Objective-C block
typedef BOOL (^HidableCellVisibilityFunctor)();
@interface BlockExecutor : NSObject
@property (strong,nonatomic) HidableCellVisibilityF
+ (BlockExecutor*)executorWithBlock:(HidableCellVisibilityFunctor)
@implementation BlockExecutor
@synthesize block = _
+ (BlockExecutor*)executorWithBlock:(HidableCellVisibilityFunctor)block
BlockExecutor * executor = [[BlockExecutor alloc] init];
executor.block =
只有一个额外的字典需要:@interface MyTableViewController ()
@property (nonatomic) NSMutableDictionary * hidableCellsD
@property (weak, nonatomic) IBOutlet UISwitch * birthdayS
再看看MyTableViewController的。我们需要转换indexPath有形和无形指标之间...- (NSIndexPath*)recoverIndexPath:(NSIndexPath *)indexPath
int rowDelta = 0;
for (NSIndexPath * ip in [[self.hidableCellsDict allKeys] sortedArrayUsingSelector:@selector(compare:)])
BlockExecutor * executor = [self.hidableCellsDict objectForKey:ip];
if (ip.section == indexPath.section
&& ip.row &= indexPath.row + rowDelta
&& !executor.block())
rowDelta++;
return [NSIndexPath indexPathForRow:indexPath.row+rowDelta inSection:indexPath.section];
- (NSIndexPath*)mapToNewIndexPath:(NSIndexPath *)indexPath
int rowDelta = 0;
for (NSIndexPath * ip in [[self.hidableCellsDict allKeys] sortedArrayUsingSelector:@selector(compare:)])
BlockExecutor * executor = [self.hidableCellsDict objectForKey:ip];
if (ip.section == indexPath.section
&& ip.row & indexPath.row - rowDelta
&& !executor.block())
rowDelta++;
return [NSIndexPath indexPathForRow:indexPath.row-rowDelta inSection:indexPath.section];
一个IBAction上UISwitch值变化:- (IBAction)birthdaySwitchChanged:(id)sender
NSIndexPath * indexPath = [self mapToNewIndexPath:[NSIndexPath indexPathForRow:1 inSection:1]];
if (self.birthdaySwitch.on)
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
UITableViewDataSource和- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
int numberOfRows = [super tableView:tableView numberOfRowsInSection:section];
for (NSIndexPath * indexPath in [self.hidableCellsDict allKeys])
if (indexPath.section == section)
BlockExecutor * executor = [self.hidableCellsDict objectForKey:indexPath];
numberOfRows -= (executor.block()?0:1);
return numberOfR
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
indexPath = [self recoverIndexPath:indexPath];
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
indexPath = [self recoverIndexPath:indexPath];
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
- (void)viewDidLoad
[super viewDidLoad];
// initializing dictionary
self.hidableCellsDict = [NSMutableDictionary dictionary];
[self.hidableCellsDict setObject:[BlockExecutor executorWithBlock:^(){return self.birthdaySwitch.}] forKey:[NSIndexPath indexPathForRow:1 inSection:1]];
- (void)viewDidUnload
[self setBirthdaySwitch:nil];
[super viewDidUnload];
7.&最好的办法是如下描述的博客&8.&对于最简单的情况下,当你隐藏单元格在表视图的底部,你可以实现代码如下的contentInset后您隐藏单元格:- (void)adjustBottomInsetForHiddenSections:(NSInteger)numberOfHiddenSections
CGFloat bottomInset = numberOfHiddenSections * 44.0; // or any other 'magic number
self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.contentInset.top, self.tableView.contentInset.left, -bottomInset, self.tableView.contentInset.right);
TA的最新馆藏[转]&[转]&[转]&[转]&1.在加载cell的地方(即 (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath里面)加上下面几句代码& & & &&[cell setBackgroundColor:CLEARCOLOR];& & & & cell.selectedBackgroundView = [[UIViewalloc] initWithFrame:cell.frame];& & & & cell.selectedBackgroundView.backgroundColor =COLOR(255,255, 255, 1.0);2.制定表格默认选中某一行//设置选中第一行&&& & & & & &&[self.tableView&selectRowAtIndexPath:[NSIndexPathindexPathForItem:0inSection:0]animated:YESscrollPosition:UITableViewScrollPositionTop];& & & & & &if ([self.tableView.delegaterespondsToSelector:@selector(tableView:didSelectRowAtIndexPath:)])& & & & & & {& & & & & & & & [self.tableView.delegatetableView:self.tableView&didSelectRowAtIndexPath:[NSIndexPathindexPathForItem:0inSection:0]];& & & & & & }
设置&input type=&file&&的
最新教程周点击榜
微信扫一扫2015年4月 移动开发大版内专家分月排行榜第二
2015年5月 移动开发大版内专家分月排行榜第三2015年3月 移动开发大版内专家分月排行榜第三2014年10月 移动开发大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。Pages: 1/2
主题 : tableview cell一半能点击一半不能点击,这有是什么坑
级别: 新手上路
可可豆: 166 CB
威望: 166 点
在线时间: 95(时)
发自: Web Page
来源于&&分类
tableview cell一半能点击一半不能点击,这有是什么坑&&&
tableview cell一半能点击一半不能点击,这有是什么坑
级别: 圣骑士
UID: 595660
可可豆: 1330 CB
威望: 1006 点
在线时间: 1024(时)
发自: Web Page
回 楼主(南山派_啊细) 的帖子
打开图层结构看看
级别: 精灵王
UID: 54474
可可豆: 3655 CB
威望: 3652 点
在线时间: 1041(时)
发自: Web Page
回 楼主(南山派_啊细) 的帖子
用的plain样式?
级别: 新手上路
可可豆: 166 CB
威望: 166 点
在线时间: 95(时)
发自: Web Page
回 1楼(雪夜风暴) 的帖子
开了图层 一开始以为是有view挡住,但是没有
级别: 新手上路
可可豆: 166 CB
威望: 166 点
在线时间: 95(时)
发自: Web Page
回 2楼(coco89718) 的帖子
是自定义的
级别: 精灵王
UID: 30808
可可豆: 5898 CB
威望: 5897 点
在线时间: 1678(时)
发自: Web Page
是不是子视图超出父视图范围了,table一半不在父视图里
级别: 精灵王
UID: 54474
可可豆: 3655 CB
威望: 3652 点
在线时间: 1041(时)
发自: Web Page
回 4楼(南山派_啊细) 的帖子
tableview样式只有plain和group,哪有自定义的啊
级别: 新手上路
可可豆: 166 CB
威望: 166 点
在线时间: 95(时)
发自: Web Page
回 6楼(coco89718) 的帖子
是plain样式
级别: 骑士
UID: 511715
可可豆: 472 CB
威望: 472 点
在线时间: 566(时)
发自: Web Page
级别: 新手上路
可可豆: 166 CB
威望: 166 点
在线时间: 95(时)
发自: Web Page
UITableView *letfTableV = [[UITableView alloc] initWithFrame:CGRectMake(0,0, YJHScreenW,self.ringthTableH) ];&&&&letfTableV.dataSource =&&&&letfTableV.delegate =&&&&// 注册cell&&&&letfTableV.scrollEnabled = NO;&&&&letfTableV.autoresizesSubviews = NO;&&&&[letfTableV registerNib:[UINib nibWithNibName:@&YJHNewsViewCell& bundle:nil] forCellReuseIdentifier:letfID];&&&&//&&&&// 设置tableView的顶部额外滚动区域&&&&letfTableV.rowHeight = letfTableH;&&&&[self.tableScollView addSubview:letfTableV];&&&&self.letfTableV = letfTableV;&&&&----------tableScollView----------是一个ScollView#pragma mark ----&&请求数据 -----(void)loadNewsData {&& &&&&NSString*url = [NSString stringWithFormat:@&%@/api/public/findTop30ImportantNews/1&,Base154_URL];&&&&NSMutableDictionary *dict = [NSMutableDictionary new];&&&&dict[@&page&] = @0;&&&&dict[@&size&] = @15;&&&&&&&&[[YJHNetworking sharedManager]postDataWithUrl:url parameters:dict success:^(id json) {&&&&&&&&&&&&&&&&self.NewsModelArr =&& [YJHNewsModel mj_objectArrayWithKeyValuesArray:json];&&&&&&&&&&&&&&&&&&&&&&&&_bottomScollView.contentSize = CGSizeMake(YJHScreenW, self.NewsModelArr.count *80+YJHRealValueH(150));&&&&&&&&&&&&&&&&_letfTableV.height = self.NewsModelArr.count*80;&&&&&&&&//&&&&&&&&YJHLog(@&%f---%f--&,_letfTableV.height, _bottomScollView.contentSize.height);//&&&&&&&&&&&&&&&&[self.letfTableV reloadData];&&&&} failure:^(NSError *error) {&&&&&&&&&&&&}];&&&&}
Pages: 1/2
关注本帖(如果有新回复会站内信通知您)
个人IDP证书一年费用? 正确答案:99美金
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版

我要回帖

更多关于 dns怎么设置才能上网 的文章

 

随机推荐