1

2つの異なるカスタムセルを使用してUITableViewControllerを作成しようとしています。私は多くの投稿を見てきましたが、特にこれは、2つの異なる再利用識別子の使用を示唆しています。私はそれをやっています、そして私はまだ最初のカスタムセルのサイズを取得しているようです。2番目のセルのラベルなどは表示されませんが、サイズは同じようです。データの表示方法は異なりますが、セルサイズは同じです。

問題がどこにあるのかわからないので、必要以上のコードが含まれている可能性がありますので、あらかじめお詫び申し上げます。

TableViewControllerのコードは次のとおりです。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 1;
}

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

    // Return the number of rows in the section.
    //set equal to the information in the array
    return [jsonDataArray count];
}

- (void) addHeaderAndFooter
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
    v.backgroundColor = [UIColor clearColor];
    //[self.tableView setTableHeaderView:v];
    [self.tableView setTableFooterView:v];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *SCellIdentifier = @"SCell";
    static NSString *PCellIdentifier = @"PCell";

    NSLog(@"%@",indexPath);
    NSLog(@"JSONDATAARRAY: %i", jsonDataArray.count);
    NSDictionary *jsoninfo = [jsonDataArray objectAtIndex:indexPath.row];
    if (indexPath.row == 0)
    {
        OBPromoCell *cell = nil;
        cell = [tableView dequeueReusableCellWithIdentifier:PCellIdentifier forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[OBPromoCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PCellIdentifier];
        }

        //get required keys from dictionary and assign to vairables
        NSString *title = [jsoninfo objectForKey:@"title"];
        NSString *subtitle = [jsoninfo objectForKey:@"subtitle"];
        NSURL *imageURL = [NSURL URLWithString:[jsoninfo objectForKey:@"image_URL"]];

        //download the images. This will most lilely need to be made asynchronous.... I don't think it is now.

        NSData *imgData = [NSData dataWithContentsOfURL:imageURL];
        UIImage *img = [[UIImage alloc] initWithData:imgData];

        //fill in text to cells
        cell.CustomCellTopLabel.text = title;
        cell.CustomCellBottomLabel.text = subtitle;
        cell.CellImageView.image = img;

        return cell;
    }

    else
    {
        OBStandardCell *cell = nil;
       cell = [tableView dequeueReusableCellWithIdentifier:SCellIdentifier forIndexPath:indexPath];
        if (cell == nil) {
            cell = [[OBStandardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SCellIdentifier];
        }   

        //get required keys from dictionary and assign to vairables
        NSString *title = [jsoninfo objectForKey:@"title"];
        NSString *subtitle = [jsoninfo objectForKey:@"subtitle"];
        NSURL *imageURL = [NSURL URLWithString:[jsoninfo objectForKey:@"series_image_URL"]];

        //download the images. This will most lilely need to be made asynchronous.... I don't think it is now.

        NSData *imgData = [NSData dataWithContentsOfURL:imageURL];
        UIImage *img = [[UIImage alloc] initWithData:imgData];

        //fill in text to cells
        cell.CustomCellTopLabel.text = title;
        cell.CustomCellBottomLabel.text = subtitle;
        cell.CellImageView.image = img;

        return cell;
    }
}

これが私のストーリーボードが参照用にどのように設定されているかの画像です。繰り返しますが、それらには異なる再利用識別子があります。

ストーリーボード

助けてくれてありがとう!!!

4

2 に答える 2

1

ほとんどあなたは物事をしました。問題はデータ表示に関連しています。

UITableViewの「heightForRowAtIndexPath」メソッドを実装し、セルの表示に応じて高さを設定する必要があります。

Method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

それがあなたの問題を解決することを願っています。

乾杯。

于 2012-12-24T06:57:40.930 に答える
0

UITableViewにはプロパティがあります

@property(nonatomic) CGFloat rowHeight

設定できますが、テーブル内のすべての行の高さが設定されます。

異なる行の高さが必要な場合は、UITableViewDelegateのこのメソッドを実装する必要があります

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
于 2012-12-24T06:46:11.033 に答える