开发者

Updating uitableview custom cell

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 u开发者_Go百科sed 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];
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜