自定义UITableView问题

时间:2010-05-07 09:41:36

标签: iphone uitableview

我有一个UITableView,我希望有三个部分 - 所有部分都由自定义单元格组成。

第一部分需要是正常的单元格高度和宽度,但第二部分(使用推文,追随者等)我想在一行中插入两行,如下图中的第二部分所示。我已经尝试过更改单元格的宽度,但它不起作用。

我已粘贴下面的代码来显示单元格,但此刻它不会抛出任何错误,只是不做我想要它做的事情! (它还有一个警告,“在最后一个返回单元格之后,控制到达非空函数的终点。”

图片(第二个“推文,关注者等”部分是我要重新创建的部分): alt text 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 个答案:

答案 0 :(得分:1)

我严重怀疑第二部分实际上是2x2细胞。它更可能只有两行,每一行看起来像两个单元格。

只需在带有四个UILabel和中央分隔线的笔尖中创建自定义单元格。