简体   繁体   中英

UITable not calling delegate methods

I have a UIView where I init a table and set the UIView as it's delegate. My .h file:

...
@interface vOperatingRooms : UIView <UITableViewDataSource, UITableViewDelegate>{
...

the table init is in a method called showSelf, and I've tested where the TV does get displayed, here's the init:

...
dataTable = [[UITableView alloc] init];
    CGRect dataTableFrame = dataTable.frame;
    dataTableFrame.origin.x = (self.frame.size.width/2)-100;
    dataTableFrame.origin.y = 115.0;
    dataTableFrame.size.width = 200.0;
    dataTableFrame.size.height = 200.0;
    dataTable.frame = dataTableFrame;
    dataTable.alpha = 0.0;
    dataTable.tag = 33;
    dataTable.delegate = self;
    dataTable.dataSource = self;
    [self addSubview:dataTable];
...

and another method that reads from a plist to build the datasource for the table:

...
//set up the directory path
        NSString* pathToProjectFolder = [NSString stringWithFormat:@"Projects/%@", projectNumber];
        //set up the file path
        NSString* ORDataFilePath = [NSString stringWithFormat:@"%@/ORData.plist", pathToProjectFolder];

        //check to make sure the project directory exists and the ORData.plist file
        [fileManager createDirectory:pathToProjectFolder];
        [fileManager createPlist:ORDataFilePath];

        //pull the data from the file
        NSDictionary* ORData = [fileManager readPlist:ORDataFilePath];
        ORNames = [[NSMutableArray alloc] init];

        for(NSString* thisOR in ORData){

            if (![thisOR isEqualToString:@"File Name"]) {
                [ORNames addObject:thisOR];
            }
        }

        //fade in table
        //fade in
        [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveEaseOut

            animations:^{
                dataTable.alpha = 1.0;
            }

            completion:^ (BOOL finished) {
            }

         ];

...

I've logged the results and I am getting the data I am looking for - this is the console of the NSArray ORNames:

2012-12-06 15:01:23.370 IntegrationSiteReport[18697:c07] (
    Test4,
    Test6
)

Here's the delegate methods:

#pragma mark Table View Management
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return ORNames.count;
    NSLog(@"%i", ORNames.count);
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [ORNames objectAtIndex:indexPath.row];
    cell.textLabel.textColor = [colorManager setColor:66.0 :66.0 :66.0];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:20.0];
    return cell;
}

I know they are not getting called as nothing is logging from within them. Is there something I am missing here?

When is showSelf called? If it is after the view loading heirarchy, you might need to just add a [dataTable reloadData]; as the last line of showSelf, not sure about that though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM