Domanda

I've got a problem with my cells in my table view controller.

I've created a table view controller with some cells that the user is able to edit but this cells doesn't display...

Here my code for the view controller :

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    // Return the number of sections.
    return 0;
}

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

    // Return the number of rows in the section.
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

And the header :

@interface AircraftDetailsViewController : UITableViewController
@property (weak, nonatomic) IBOutlet UITextField *AircraftNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *AircraftImmatLabel;

If someone could help me... I don't understand why it is empty...

I've forgotten to add that my cells are "Static cells".

EDIT : Problem sovlved. I just comment these line :

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//
//    // Return the number of sections.
//    return 0;
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
//
//    // Return the number of rows in the section.
//    return 0;
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    static NSString *CellIdentifier = @"Cell";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//    
//    // Configure the cell...
//    
//    return cell;
//}

Now it works.

È stato utile?

Soluzione

If you have static tableviews in the storyboard, don't implement any datasource methods. UITableViewController has its own implementation of these which you have overridden in your code above. If you do override the methods, you must call the super implementation, to get the value of your static cells, and then modify as you see fit.

Even if you weren't using static cells, you still wouldn't see anything, because you've told your table view that there are no sections and no rows in the table.

Altri suggerimenti

For starters you are returning 0 sections and 0 rows so nothing will be displayed. You should return values > 0 according to your data layout.

After you fix that make sure that "Cell" identifier is defined in IB (In the Cell's properties pane although I believe it's the default name and should be there already).

In your code you specify table have no cells at all. Return other then 0 value in number* functions

You forgot to declare protocols in .h file.
Change this
@interface AircraftDetailsViewController : UITableViewController
to
@interface AircraftDetailsViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate>

And you are returning 0 in datasource method which is wrong.

The sections and rows must be a non zero value

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

// Return the number of sections.
return 1;

}

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

{

// Return the number of rows in the section.
return 10;

}

So delete above code and set controller as table data source and table delegate in interface builder with ctrl+drag from tableview to controller. For static cells it's enough.

You told number section and row as zero to tableview via delegate methods. So It shows nothing. According to this, your cellForRowAtIndexPath: never getting called.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top