2012-12-06 120 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