2010-05-07 4 views
0

J'ai une UITableView dont je souhaite disposer en trois sections, toutes composées de cellules personnalisées. La première section doit être la hauteur et la largeur normales de la cellule, mais la deuxième section (avec les Tweets, les suiveurs, etc.) Je veux placer deux rangées dans une rangée comme dans la deuxième section de l'image ci-dessous. J'ai essayé de changer la largeur des cellules, mais cela ne fonctionne pas.Problèmes UITableView personnalisés

J'ai collé le code ci-dessous pour afficher les cellules, mais pour l'instant il ne jette pas d'erreurs ne fait pas ce que je veux qu'il fasse! (Il a aussi un avertissement de "contrôle atteint la fin de la fonction non-vide à la} après la dernière cellule de retour

L'image (la deuxième section" Tweets, Followers etc "est celle que je veux recréez): alt text http://technopedia.info/wp-content/uploads/2009/09/tweetie22.jpg

Et le code: - (UITableViewCell *) tableView: (UITableView *) Table 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; 
    } 

} 

Répondre

1

Je fais au sérieux ubt que la deuxième section est en fait 2x2 cellules. Il est beaucoup plus probable que ce soit juste 2 rangées qui ressemblent chacune à deux cellules.

Créez simplement une cellule personnalisée dans une plume avec quatre UILabel s et un diviseur central.

+0

Salut, OK, donc si c'est le cas - comment faire en sorte que lorsque l'utilisateur appuie sur la cellule qu'une action se produit? C'est à dire. une fenêtre d'email apparaît? Parce que le côté gauche (comme dans l'image "suivant") ouvrirait idéalement la fenêtre email, tandis que le côté droit (image: "tweets") ouvre une autre vue? – Graeme

+0

En faire un UIButton? –

+0

@Graeme: Vous devez ajouter deux boutons dans chaque rangée de cellules et en appuyant dessus, vous pouvez effectuer l'action requise. –