更新 uitableview 自定义单元格

发布于 2024-11-28 00:22:12 字数 1903 浏览 3 评论 0原文

我有一个问题,如果你不像我那么盲目的话,这可能相当容易。我有一个带有海关单元格的表格视图,它从数据源获取信息。在这个自定义单元格中,我有一个按钮可以更改所有单元格的数据源。按下一个单元格中的按钮将使所有其他单元格变暗。数据源已更改,但我的问题是,只有当我在表视图中拖动单元格时,单元格才会更新。按下按钮时的方法被放置在tableview中并以[tableview reloadData]结束;但它仅在拖动时更新。

感谢任何帮助

--更新-- 下面显示了按下按钮时调用的方法。 switch case 改变数据源。 Button.tag 用于查看按钮被按下的单元格。

-(void)myPackageButtonPushed:(id)sender
{
   UIButton* myButton = (UIButton*)sender;
   NSLog(@"id %d",myButton.tag);
   int test=myButton.tag;
   for (int i=0; i<[packageList count]; i++) {
        TVPackage *tvpack=[packageList objectAtIndex:i];
        [tvpack setMyPackage:NO];
    }

    switch (test) {
        case 0:
            NSLog(@"0");
            [[packageList objectAtIndex:0] setMyPackage:YES];
              [[packageList objectAtIndex:1] setMyPackage:YES];

            break;
        case 1:
            NSLog(@"1");
            [[packageList objectAtIndex:0] setMyPackage:YES];
            [[packageList objectAtIndex:1] setMyPackage:YES];
            break;
        case 2:
            NSLog(@"2");
            [[packageList objectAtIndex:2] setMyPackage:YES];
            [[packageList objectAtIndex:3] setMyPackage:YES];
            break;
        case 3:
            NSLog(@"3");
            [[packageList objectAtIndex:2] setMyPackage:YES];
            [[packageList objectAtIndex:3] setMyPackage:YES];
            break;
        case 4:
            NSLog(@"4");
            [[packageList objectAtIndex:4] setMyPackage:YES];
            [[packageList objectAtIndex:5] setMyPackage:YES];
            break;
        case 5:
            NSLog(@"5");
            [[packageList objectAtIndex:4] setMyPackage:YES];
            [[packageList objectAtIndex:5] setMyPackage:YES];
            break;
        default:
            break;
    }

    [self.tableview performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    }

I have an issue which probably is fairly easy if you're not as blind as me. I have a tableview with customs cells, which are taking information from a datasource. In this custom cell I have a button which changes the datasource for all the cells. Pushing the button in one cell should make all the other cells dark. The datasource is changed, however my problem is that the cells only updates when I drag the cells in the table view. The method when the button is pushed is placed in the tableview and ends with [tableview reloadData]; but it only updates when dragged.

Any help is appreciated

--Update--
The following shows the method called when the button is pushed. The switch case changes the datasource. The button.tag is used to see in which cell the button is pushed.

-(void)myPackageButtonPushed:(id)sender
{
   UIButton* myButton = (UIButton*)sender;
   NSLog(@"id %d",myButton.tag);
   int test=myButton.tag;
   for (int i=0; i<[packageList count]; i++) {
        TVPackage *tvpack=[packageList objectAtIndex:i];
        [tvpack setMyPackage:NO];
    }

    switch (test) {
        case 0:
            NSLog(@"0");
            [[packageList objectAtIndex:0] setMyPackage:YES];
              [[packageList objectAtIndex:1] setMyPackage:YES];

            break;
        case 1:
            NSLog(@"1");
            [[packageList objectAtIndex:0] setMyPackage:YES];
            [[packageList objectAtIndex:1] setMyPackage:YES];
            break;
        case 2:
            NSLog(@"2");
            [[packageList objectAtIndex:2] setMyPackage:YES];
            [[packageList objectAtIndex:3] setMyPackage:YES];
            break;
        case 3:
            NSLog(@"3");
            [[packageList objectAtIndex:2] setMyPackage:YES];
            [[packageList objectAtIndex:3] setMyPackage:YES];
            break;
        case 4:
            NSLog(@"4");
            [[packageList objectAtIndex:4] setMyPackage:YES];
            [[packageList objectAtIndex:5] setMyPackage:YES];
            break;
        case 5:
            NSLog(@"5");
            [[packageList objectAtIndex:4] setMyPackage:YES];
            [[packageList objectAtIndex:5] setMyPackage:YES];
            break;
        default:
            break;
    }

    [self.tableview performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    }

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

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

发布评论

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

评论(1

美男兮 2024-12-05 00:22:12

我没有正确设置界面生成器和类之间的链接。 IB 被设置为 UIViewController 而不是我的特定类。感谢您的帮助和您的时间。

I did not have the link between the Interface Builder and classes correctly set up. IB was set to a UIViewController instead of my specific class. Thank you for the help and your time.

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