UITableView 清单

发布于 2024-09-10 08:07:58 字数 1727 浏览 3 评论 0原文

我正在使用 UITableView 制作一个清单程序,并且我设法实现了直到选择并显示复选标记的所有内容。但是,当我滚动离开单元格时。复选标记消失。

我有以下代码:

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

static NSString *CellIdentifier = @"CellIdentifier";

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}

// Configure the cell.
if(tableView == Table1){

    switch(indexPath.section){
        case 0:
            cell.textLabel.text =[array1 objectAtIndex:indexPath.row];
            break;
        case 1:
            cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
            break;
        case 2:
            cell.textLabel.text = [array3 objectAtIndex:indexPath.row];
            break;
    }

    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
}

//if([indexPath compare:[selectedArray objectAtIndex:i]] == NSOrderedSame){
if([selectedArray containsObject:cell]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
        cell.accessoryType = UITableViewCellAccessoryNone;
}
//}
if(tableView == sauceTable){
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row];
}

return cell;}  

并且:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *c= [aTableView cellForRowAtIndexPath: indexPath];
c.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedArray addObject: c];
}

有什么想法吗?

I'm making a checklist program using UITableView and I managed to implement everything up to selection and making a checkmark appear. However, when I scroll away from the cells. The checkmark disappears.

I have the following code:

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

static NSString *CellIdentifier = @"CellIdentifier";

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

}

// Configure the cell.
if(tableView == Table1){

    switch(indexPath.section){
        case 0:
            cell.textLabel.text =[array1 objectAtIndex:indexPath.row];
            break;
        case 1:
            cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
            break;
        case 2:
            cell.textLabel.text = [array3 objectAtIndex:indexPath.row];
            break;
    }

    //cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
}

//if([indexPath compare:[selectedArray objectAtIndex:i]] == NSOrderedSame){
if([selectedArray containsObject:cell]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
        cell.accessoryType = UITableViewCellAccessoryNone;
}
//}
if(tableView == sauceTable){
    cell.textLabel.text = [array4 objectAtIndex:indexPath.row];
}

return cell;}  

And:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *c= [aTableView cellForRowAtIndexPath: indexPath];
c.accessoryType = UITableViewCellAccessoryCheckmark;
[selectedArray addObject: c];
}

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此刻的回忆 2024-09-17 08:07:58

解决了。使用 NSIndexPath 而不是 UITableViewCell 作为选择数组

Solved. Used NSIndexPath instead of UITableViewCell for the selectionArray

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文