Пользовательские проблемы UITableView - PullRequest
0 голосов
/ 07 мая 2010

У меня есть один UITableView, который я хочу иметь три раздела - каждый из которых состоит из пользовательских ячеек.

Первый раздел должен иметь нормальную высоту и ширину ячейки, но второй раздел (с твитами, подписчиками и т. Д.) Я хочу разместить по два ряда в одном ряду, как во втором разделе на рисунке ниже. Я пытался изменить ширину ячеек, но это не работает.

Я вставил приведенный ниже код для отображения ячеек, но на данный момент он не выдает никаких ошибок, просто не делает то, что я хочу! (У него также есть предупреждение: «управление достигает конца не пустой функции, хотя в} после последней возвращаемой ячейки.

Изображение (второй раздел «Твиты, подписчики и т. Д.» - это то, что я хочу воссоздать): альтернативный текст http://technopedia.info/wp-content/uploads/2009/09/tweetie22.jpg

И код: - (UITableViewCell *) tableView: (UITableView *) таблица cellForRowAtIndexPath: (NSIndexPath *) indexPath {

    if(indexPath.section==0) {
        static NSString *kCellIdentifier = @"SongDetailCell";
        UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:kCellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    switch (indexPath.row) {
        case 0: {
            cell.textLabel.text = NSLocalizedString(@"District:", @"district label");
            cell.detailTextLabel.text = dog.district;
        } break;
        case 1: {
            cell.textLabel.text = NSLocalizedString(@"Location:", @"location label");
            cell.detailTextLabel.text = dog.locations;
        } break;
        case 2: {
            cell.textLabel.text = NSLocalizedString(@"Dog Name:", @"name label");
            cell.detailTextLabel.text = dog.names;
        } break;
        case 3: {
            cell.textLabel.text = NSLocalizedString(@"Last Updated:", @"last updated label");
            cell.detailTextLabel.text = [incident.lastUpdated substringToIndex:[dog.lastUpdated length] - 1];
        } break;
         case 4: {
            cell.textLabel.text = NSLocalizedString(@"Type:", @"type label");
            cell.detailTextLabel.text = dog.types;
        } break;
         case 5: {
            cell.textLabel.text = NSLocalizedString(@"Status:", @"status label");
            cell.detailTextLabel.text = dog.status;
        } break;
         case 6: {
            cell.textLabel.text = NSLocalizedString(@"Size:", @"size label");
            cell.detailTextLabel.text = dog.sizes;
        } break;
         case 7: {
            cell.textLabel.text = NSLocalizedString(@"Applicances:", @"appliances label");
            cell.detailTextLabel.text = dog.appliances;
        } break;
         case 8: {
            cell.textLabel.text = NSLocalizedString(@"Started:", @"started label");
            cell.detailTextLabel.text = dog.startDate;
        } break;
    }
        return cell;
    }

    if(indexPath.section==1) {
        static NSString *CellIdentifier = @"ContactCell";

        ContactViewCell *cell = (ContactViewCell *)
        [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ContactTableCell" owner:self options:nil];

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

        switch (indexPath.row) {
            case 0: {
                cell.testLabel.text = @"Title";
            } break;
            case 1: {
                cell.testLabel.text = @"Title";
            } break;
            case 2: {
                cell.testLabel.text = @"Title";
            } break;
            case 3: {
                cell.testLabel.text = @"Title";
            } break;
            case 4: {
                cell.testLabel.text = @"Title";
            } break;
        }
        return cell;
    }

}

1 Ответ

1 голос
/ 07 мая 2010

Я серьезно сомневаюсь, что второй раздел на самом деле 2х2 ячейки.Гораздо более вероятно, что только две строки выглядят как две ячейки.

Просто создайте пользовательскую ячейку в кончике с четырьмя UILabel с и центральным делителем.

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