gpt4 book ai didi

ios - 只能点击 UITableView 中的一项

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:15:09 27 4
gpt4 key购买 nike

所以我有一个列出数据的子类 UITableView。我需要只选择一个单元格。

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// rows in section 0 should not be selectable
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if (indexPath.row == 3) {
cell.userInteractionEnabled = YES;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
NSLog(@"Hey whats up, address");
return indexPath;
}
else {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return nil;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

到目前为止,我执行此操作的代码有效,但只有在至少单击一次单元格之后。将它放在 didSelectCell 中允许在按住 1-2 秒时选择单元格。

最佳答案

您应该在 cellForRowAtIndexPath 中执行此操作。像这样:

-(UITableViewCell*)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

// your code
if(indexPath.row != 3)
{
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
{

}

然后在 didSelectRowAtIndexPath 上:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 3)
{
//do your stuff
{

}

关于ios - 只能点击 UITableView 中的一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11150993/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com