0

次のコードを使用して、画像とその横にテキストを含むカスタムリストを表示しましたが、指定された5つのサンプルデータで満たされたリストを表示できません。誰かが私を助けることができますか?

#import "RestListViewController.h"
#import "RestListCustomTableCell.h"

@implementation RestListViewController

/*
// The designated initializer. Override to perform setup that is required before the view is    loaded.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
      // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */


  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad {
 [super viewDidLoad];
    }
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:                     (NSIndexPath       *)indexPath {
    //NEVER REACHES HERE!!!!!!!!!!
NSLog(@"BUILD THE TABLE!!!");
static NSString *CellIdentifier = @"Cell";
RestListCustomTableCell *cell = (RestListCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[RestListCustomTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell…

switch (indexPath.row) {

    case 0:
        cell.primaryLabel.text = @"Meeting on iPhone Development";
        cell.secondaryLabel.text = @"Sat 10:30";
        cell.myImageView.image = [UIImage imageNamed:@"restabapiknik.png"];
        break;
    case 1:
        cell.primaryLabel.text = @"Call With Client";
        cell.secondaryLabel.text = @"Planned";
        cell.myImageView.image = [UIImage imageNamed:@"restburgerking.png"];
        break;
    case 2:
        cell.primaryLabel.text = @"Appointment with Joey";
        cell.secondaryLabel.text = @"2 Hours";
        cell.myImageView.image = [UIImage imageNamed:@"restburgerstory.png"];
        break;
    case 3:
        cell.primaryLabel.text = @"Call With Client";
        cell.secondaryLabel.text = @"Planned";          
        cell.myImageView.image = [UIImage imageNamed:@"restkfc.png"];
        break;
    case 4:
        cell.primaryLabel.text = @"Appointment with Joey";
        cell.secondaryLabel.text = @"2 Hours";
        cell.myImageView.image = [UIImage imageNamed:@"restmcdonalds.png"];
        break;
    default:
        break;
}
return cell;
 }

/*
  // Override to allow orientations other than the default portrait orientation.
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  // Return YES for supported orientations
  return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  */

 - (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
 }

  - (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
 }


 - (void)dealloc {
 [super dealloc];
 }

@end

また、ヘッダーファイルは次のとおりです。

 #import <UIKit/UIKit.h>

 @interface RestListViewController : UITableViewController {
NSMutableArray      *   myStrings;
 }
 @property(nonatomic, retain)NSMutableArray * myStrings;

 @end
4

1 に答える 1

2

Tableviewに表示する行数を表すデリゲートのメソッドを追加する必要があります

//.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10; // numbers of rows
}
于 2012-04-07T23:49:08.697 に答える