Пользовательские ячейки UITableView не отображаются - PullRequest
0 голосов
/ 28 декабря 2010

У меня есть UITableViewController с двумя IBOutlet для двух разных UITableViewCell, которые были сделаны в IB. Однако они не отображаются в tableView. Если вы можете найти ошибку, я буду очень признателен.

<code>
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *categoryIdentifier = @"Category";
    static NSString *songDetailsCellIdentifier = @"sdci";
    static NSString *socialCellIdentifier = @"sdcssi";
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    switch (indexPath.row) {
        case 0:
            //imageView = [[UIImage alloc] initWithData:imageData];
            //songNameLabel.text = songName;
            //artistNameLabel.text = artistName;
            //albumNameLabel.text = albumName;
            //numberInChartsLabel.text = [[NSString alloc] initWithFormat:@"%d", numberInCharts];
            break;
        case 1:
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:categoryIdentifier] autorelease];
            cell.textLabel.text = [[NSString alloc] initWithFormat:@"Category"];
            cell.detailTextLabel.text = [[NSString alloc] initWithFormat:@"%@", category];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case 2:
            cell.textLabel.text = [[NSString alloc] initWithFormat:@"Preview This Track"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case 3:
            cell.textLabel.text = [[NSString alloc] initWithFormat:@"View This Song In iTunes"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case 4:
            cell.textLabel.text = [[NSString alloc] initWithFormat:@"View Artist In iTunes"];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            break;
        case 5:
            break;
    }
    // Configure the cell...
    if (indexPath.row == 0) {
        songDetailsCell = [[[UITableViewCell alloc] initWithFrame:songDetailsCell.frame reuseIdentifier:songDetailsCellIdentifier] autorelease];
        return songDetailsCell;
    }
    if (indexPath.row == 5) {
        socialCell = [[[UITableViewCell alloc] initWithFrame:socialCell.frame reuseIdentifier:socialCellIdentifier] autorelease];
        return socialCell;

} иначе if (indexPath.row> = 1 && indexPath.row <= 5) { возвратная ячейка; } вернуть ноль; } </code>

Ответы [ 2 ]

0 голосов
/ 29 декабря 2010

Если я правильно прочитал, система не сможет узнать, что у вас есть пользовательская ячейка. Ваши ячейки размещаются и инициализируются с UITableViewCell в качестве типа. Они должны относиться к типу MyCustomCell или к тому, что вы называли объектами своей ячейки при создании их в Интерфейсном Разработчике.

Таким образом, в этом разделе кода вы должны ссылаться на свою ячейку вместо UITableViewCell:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

Существует отличная бесплатная заставка , которую Pragmatic Studio сделала для создания пользовательских ячеек таблицы. Это называется Custom Table Cells в Интерфейсном Разработчике. Это около 20 минут.

0 голосов
/ 29 декабря 2010

Переведите переключатель в положение if{indexPath.section}, включая UITableViewCell *cell...

Тогда остальное ниже должно быть indexPath.section вместо indexPath.row

if(indexPath.section==0) {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    switch (indexPath.row) {
        case 0:

....


 if (indexPath.section == 1) {
    songDetailsCell = [[[UITableViewCell alloc] initWithFrame:songDetailsCell.frame reuseIdentifier:songDetailsCellIdentifier] autorelease];
    return songDetailsCell;
}


....

Следуйте этому формату.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...