UITableView不显示任何内容

当我运行应用程序来显示UITableView时,结果什么都没有。 它不会运行:

- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section {} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
  • 开发环境是IOS SDK 6.1。 /模拟器版本是6.0。
  • 我在故事板中使用了表格视图控制器。
  • 我创建了一个名为“RetrieveDataFromDBTableVC”的类,并将表视图控制器的自定义类设置为“RetrieveDataFromDBTableVC”。 在这里输入图像描述

  • 我认为代表和数据源已经为我设置了,所以我不需要再次设置对吗? (委托和数据源的连接是表视图)。

  • 在这里输入图像描述

  • 在“RetrieveDataFromDBTableVC”类中,我定义如下:

      - (void)viewDidLoad
      {
        [super viewDidLoad];
        [self retrieveData];
      }
    
      -(void)retrieveData
      {
          NSURL * url = [NSURL URLWithString:getDataURL];
          NSData * data = [NSData dataWithContentsOfURL:url];
    
          citiesArray = [[NSMutableArray alloc]init];
    
          // Assign data
          NSString * cID = @"aa";
          ...
    
          cities * myCity = [[cities alloc]initWithCityID:cID andCityID:cName andCityState:cState andCityPopulation:cPopulation andCityCountry:cCountry];
    
          // Add city object to our cities array
          [citiesArray addObject:myCity];
    
          // Create a myTableView outlet for this table view to reload data 
          // self.tableView is also correct right?
          [self.myTableView reloadData];
       }
    
       - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section
       {
          // It will not run this function !!
          return [citiesArray count];
       }
    
       // It will not go into this function either !!
       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
         // Set the identifier name in UITableViewCell also
         static NSString *CellIdentifier = @"cities";
         UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
         // Retrieve the current city object for use with this indexPath.row
        cities * currentCity = [citiesArray objectAtIndex:indexPath.row];
    
        cell.textLabel.text = currentCity.cityName;
    
        return cell;
      }
    
  • 我认为连接是问题,但我不知道如何解决这个问题。 谢谢 !!


    确保从以下位置更改文件的这一行:(在.h文件中)

    @interface YourClass : something
    

    至:

    @interface YourClass : something <UITableViewDataSource, UITableViewDelegate>
    

    如果你还没有。


    除非它在IB中作为UITableViewController的实例以及UITableViewController的子类来绘制,否则委托和数据源不会自动连接。 在IB中或在viewDidLoad上的代码中明确地连接这些。

    链接地址: http://www.djcxy.com/p/87727.html

    上一篇: UITableView shows nothing

    下一篇: table view does not display data,iphone