2010-12-28 15 views
0

Ich habe einen UITableViewController mit zwei IBOutlet zu zwei verschiedenen UITableViewCells, die in IB gemacht wurden. Sie werden jedoch nicht in der TableView angezeigt. Wenn Sie den Fehler finden können, werde ich es wirklich zu schätzen wissen.UITableView Benutzerdefinierte Zellen werden nicht angezeigt


    - (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; 

} else if (indexPath.row> = 1 & & indexPath.row < = 5) { return Zelle; } Rückkehr Null; }

Antwort

0

Setzen Sie den Schalter in einem if{indexPath.section} statetment, die unterhalb einschließlich UITableViewCell *cell...

Dann wird der Rest indexPath.section statt 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; 
} 


.... 

dieses Format Folgen sein muss.

+0

Ich habe das versucht, die Zelle wird immer noch nicht angezeigt. – MKDev

+0

versuchen Sie diesen Code, es funktioniert: http://pastie.org/1412313 – WrightsCS

+0

stellt sich heraus, es war, weil ich nicht die Feder in der vorherigen Ansicht geladen wurde. – MKDev

0

Wenn ich dies richtig gelesen habe, gibt es keine Möglichkeit für das System zu wissen, dass Sie eine benutzerdefinierte Zelle haben. Ihre Zellen werden mit UITableViewCell als Typ zugewiesen und initialisiert. Sie sollten vom Typ MyCustomCell oder wie auch immer Sie Ihre Zellobjekte benannt haben, wenn Sie sie in Interface Builder erstellt haben.

Also, würden Sie Ihre Zelle statt UITableViewCell in diesem Abschnitt des Codes verweisen:

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

Es gibt eine great, free screencast ist, die Pragmatische Studio hat benutzerdefinierte Tabellenzellen auf zu machen. Es heißt benutzerdefinierte Tabellenzellen im Interface Builder. Es ist ungefähr 20 Minuten.

Verwandte Themen