0

ラベルを含むカスタム セルを作成しましたが、それをテーブル ビューに追加すると、それが表示されず、View Controller が表示されませんTableViewControllerIB を使用してテーブル ビューを設定し、そのデリゲートとデータソースを正しく設定しました。

私はこれをやっています:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ExampleAppDataObject* theDataObject = [self theAppDataObject];
    return theDataObject.myAudio.count;
}


    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

        static NSString *CellIdentifier = @"Cell";

        ExampleAppDataObject* theDataObject = [self theAppDataObject];

        NSString *destinationPath = [theDataObject.myAudio objectAtIndex:indexPath.row];

        NSArray *parts = [destinationPath componentsSeparatedByString:@"/"];

        NSString *filename = [parts lastObject];

        AudioInfoCell *cell = (AudioInfoCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil) {
            cell = [[AudioInfoCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
        }

        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

        cell.audioName.text = filename;

        return cell;

    }
4

2 に答える 2

0

最初にtableView:numberOfRowsInSectionメソッドに設定された行数を確認します

以下のようなカスタムセルを設定した後..

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AudioInfoCell *cell = (AudioInfoCell *) [tableView dequeueReusableCellWithIdentifier:nil];


    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"AudioInfoCell" owner:self options:nil];

        for (id currentObject in topLevelObjects){
            if ([currentObject isKindOfClass:[UITableViewCell class]]){
                cell =  (AudioInfoCell *) currentObject;
                break;

            }
        }
    }

    ExampleAppDataObject* theDataObject = [self theAppDataObject];

    NSString *destinationPath = [theDataObject.myAudio objectAtIndex:indexPath.row];

    NSArray *parts = [destinationPath componentsSeparatedByString:@"/"];

    NSString *filename = [parts lastObject];

    cell.audioName.text = filename;
    return cell;
}
于 2012-12-13T13:19:23.857 に答える
0

2 つの確認事項:

  1. 再利用識別子がInterface Builderのものと一致することを確認してください
  2. numberOfRowsInSection正しい数字をnumberOfSectionsInTableView 返すことを確認してください

また、私は使用しません:

if (cell == nil) {
        cell = [[AudioInfoCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}

セルをインスタンス化するため。これは、AudioCell TableViewCell実装したサブクラスで処理する必要があります。この種のカスタム セルを実装する方法の例は次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"FlightPickerCell";
    FlightPickerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.tripIDLabel.text = @"Some TripID";
    cell.hospitalLabel.text = @"Some Hospital";
    cell.cityLabel.text = @"Some City";
    return cell;
}
于 2012-12-13T13:21:27.403 に答える