Iphone 如何在uitableview中启用和禁用单元格
我有一个项目,在该项目中,我想在视图加载的开始时禁用Iphone 如何在uitableview中启用和禁用单元格,iphone,Iphone,我有一个项目,在该项目中,我想在视图加载的开始时禁用UITableView的单元格,按下按钮后,UITableView的单元格应被启用并正常工作 我怎样才能做到这一点?您可以使用 table.AllowSelection=否; 在视图中,将显示方法,然后在按钮单击事件中将其设为“是”。如果要禁用整个表,则可以使用: //In UIButton pressed event boolEnabled=YES; //Declare it in header file [yourTableView re
UITableView
的单元格,按下按钮后,UITableView
的单元格应被启用并正常工作
我怎样才能做到这一点?您可以使用
table.AllowSelection=否;
在视图中,将显示方法,然后在按钮单击事件中将其设为“是”。如果要禁用整个表,则可以使用:
//In UIButton pressed event
boolEnabled=YES; //Declare it in header file
[yourTableView reloadData]; //reload UITableView
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//After creating a cell
if(boolEnabled==YES) //Will enable for any action
{
cell.userInteractionEnabled=YES;
}
else
{ //disable for any action
cell.userInteractionEnabled=NO; //Default boolEnabled=NO;
}
}
table.userInteractionEnabled = FALSE;
然后单击按钮:
table.userInteractionEnabled = TRUE;
我要做的是让一个
@属性(非原子)BOOL tableIsActive
在我的-(UITableViewCell*)表视图中:(UITableView*)表视图cellforrowatinexpath:(nsindepath*)indepath
我会这样做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.tableIsActive)
{
//style cells for enabled table
}
else
{
//style cells for enabled table
}
}
然后在我的-(void)tableView:(UITableView*)tableView中选择了rowatindexpath:(nsindepath*)indepath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.tableIsActive)
{
//handle selection
}
else
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
}
然后我将有一个函数-(void)enableTable:(id)sender
,我将它绑定到我的按钮上
-(void) enableTable:(id)sender
{
if(self.tableIsActive)
self.tableIsActive = NO;
else
self.tableIsActive = YES;
}
然后在启用call
[yourTable reloadData]之后代码>您可以使用下面的代码来完成,只需检查TableView delgate方法中的条件
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *categoryIdentifier = @"Category";
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//Way to stop to choose the cell selection
if(indexpath.row==0)
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
Or
cell.userIneractionEnabled=False;
}
//while rest of the cells will remain active, i.e Touchable
return cell;
}
还有一个属性单元格。启用
,您也可以将其设置为是
或否
。请澄清您所说的启用和禁用是什么意思?