UITableView shows nothing
When I run the application to show the UITableView, it turns out nothing. It will not run :
- (NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section {} 
and
- (UITableViewCell *)tableView:(UITableView *)tableView 
cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
 I created a class called "RetrieveDataFromDBTableVC" and set the table view controller's custom class to "RetrieveDataFromDBTableVC".  
I think the delegate and data source already set up for me, so I do not need to set again right? (The connection of delegate and datasource is Table View).

In "RetrieveDataFromDBTableVC" class I defined like the following:
  - (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;
  }
I think the connection is the problem, but I do not know how to figure that out. Thanks !!
Make sure to change this line of your file from: (in the .h file)
@interface YourClass : something
to:
@interface YourClass : something <UITableViewDataSource, UITableViewDelegate>
If you haven't already.
Unless it's painted as an instance of UITableViewController in IB, and a subclass of UITableViewController, the delegate and datasource are not automatically connected. Connect those explicitly in IB or in code on viewDidLoad.
链接地址: http://www.djcxy.com/p/87728.html上一篇: Swift动态tableview在UIViewController
下一篇: UITableView不显示任何内容
