2012-12-06 122 views
0

我有一个UIView,我初始化一个表并将UIView设置为委托。我的.h文件中:UITable不调用委托方法

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

表初始化是在一个名为showSelf方法,我测试过在电视不能得到显示,这里的初始化:

... 
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]; 
... 

和读取另一种方法从plist中建表的数据源:

... 
//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) { 
      } 

     ]; 

... 

我记录的结果和我得到我要找的数据 - 这是NSArray的ORNames的控制台:

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

这里的委托方法:

#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; 
} 

我知道他们没有得到被称为没有从内他们记录。有什么我在这里失踪?

回答

4

showSelf何时被调用?如果它是在视图加载heirarchy之后,您可能需要添加一个[dataTable reloadData];作为showSelf的最后一行,但不确定。

+0

一些如何删除我的评论,我发布后,我发布(典型)。无论如何,我会给你胜利的。 :D – PruitIgoe

+0

@PruitIgoe好的,谢谢。 – GeneralMike

+0

谢谢!这帮助了我。 – lppier