简体   繁体   English

自定义UITableView不显示

[英]Custom UITableView does not display

I have the following code to show me a custom list with images and some text next to it but I can not see my list filled with the five sample data given.我有以下代码向我显示一个带有图像和旁边一些文本的自定义列表,但我看不到我的列表充满了给定的五个示例数据。 Can someone help me???有人能帮我吗???

#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

And the header file is as follows:而header文件如下:

 #import <UIKit/UIKit.h>

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

 @end

You need to add the method of the delegate representing the number of rows to display in Tableview您需要添加表示要在 Tableview 中显示的行数的委托的方法

//.m
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10; // numbers of rows
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM