簡體   English   中英

UITable不調用委托方法

[英]UITable not calling delegate methods

我有一個UIView,我在其中初始化一個表並將UIView設置為其委托。 我的.h文件:

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

表格init是一種名為showSelf的方法,我已經測試了電視的顯示位置,這是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];
...

另一種從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;
}

我知道他們沒有被召喚,因為他們內部什么也沒有記錄。 我在這里缺少什么嗎?

showSelf何時調用? 如果是在視圖加載層次結構之后,則可能只需要添加[dataTable reloadData]; 作為showSelf的最后一行,盡管不確定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM