Uitableview with Static Cells Does Not Appear

Content of static cells not appearing UITableView

I think you have problem with constraints! If you have wrong constraint for elements inside cell, elements will not shown!

UITableView with static cells does not appear

Do you want to try using the TableViewController rather than the Generic View controller ?

Static table not showing

You may miss some stuff:

1) Check whether your tableView has set the class named as that on in your code. You find the input field to type the name of the class in Attributes inspector of the tableView.

2) Check whether you implemented methods, that comform to UITableViewDelegate and UITableViewDataSource Protocol.

func numberOfSections(in tableView: UITableView) -> Int {
// I see you only have 1 section now
return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//you should return appropriate number
return 3
}

3) Check whether your table is properly connected from Storyboard to your UIViewController =>

if your tableView is inside UIViewController, check whether you set delegate and datasource for tableView in your controller (CTRL drag from table to FileOwner - rounded yellow icon in storyboard scene frame.)

Static cells: Content does not appear

For static table views, you must not implement any of the datasource methods. The base implementation of UITableViewController has its own versions of these methods which return the appropriate content by reading the storyboard file. The methods are those which provide the table content, e.g. numberOfRows, numberOfSections, heightForRow, cellForRow and so forth.

In your case, you'd implemented tableView:cellForRowAtIndexPath: and returned empty cells each time. This meant the size of your cells was correct, but the content was gone.

Also, none of the outlets to content in your static table view will be set until after [super viewWillAppear:animated] has been called. They will still be nil at viewDidLoad, where you are calling them from, because the table view hasn't asked for any of it's content at that point.

Content of static cells not appearing UITableView

I think you have problem with constraints! If you have wrong constraint for elements inside cell, elements will not shown!

How to properly implement a static cell with Swift 3

It's much easier if the table view contains only static cells:

  • In Interface Builder select the table view and set the Content to Static Cells
  • Create IBOutlets and IBActions in the controller class and connect them.
  • Implementing table view data source methods and subclassing cells is not needed.

iOS UITableViewController static tableView does not scroll

Finally, after more than 3 days of daily debugging, I found out the problem ...

This is definitely the trickiest bug I've ever encountered, but it seems that Cocoapods power comes with responsibility. I've imported the following library:

https://github.com/shaps80/iMessageStyleReveal

And unfortunately the library itself breaks the table view scroll. When I debugged the actuals views, it was even more hard to notice the added gesture recognizer of the library, as it had a common name and cancelTouchesInView set to FALSE. The actual problem was inside the extension, where the UITableView methods were overriden.

Removed it and everything works again. Phew.

static uitableviewcells with custom classes not showing content

It seems that we can't generate custom static cells and try to access their outlets and change them (because their static) please correct me if i'm wrong because I couldn't access them at all.

I've solved my Problem by changing the TableView Type to Dynamic Cells, i didn't put any prototype cells in the tableview and I have created 3 different Cell Classes (with their nibs)

I have registered the nib files with the tableview by adding this to the viewdidload method:

[self.tableView registerNib:[UINib nibWithNibName:@"MyCellType1" bundle:nil] forCellReuseIdentifier:@"CellType1"];
[self.tableView registerNib:[UINib nibWithNibName:@"MyCellType2" bundle:nil] forCellReuseIdentifier:@"CellType2"];
[self.tableView registerNib:[UINib nibWithNibName:@"MyCellType3" bundle:nil] forCellReuseIdentifier:@"CellType3"];

then i fully customized my tableview methods:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 2;
break;
case 1:
return 1;
case 2:
return [self.myarray count];
default:
break;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case 0: {
MyCellType1 *cell = (MyCellType1 *) [tableView dequeueReusableCellWithIdentifier:@"CellType1" forIndexPath:indexPath];
//this section always has 2 rows
if (indexPath.row==0) {
cell.lblTitle.text = @"ID";
cell.lblValue.text = [NSString stringWithFormat:@"%i",1277];
} else {
cell.lblTitle.text = @"Date";
cell.lblValue.text = @"02/03/2015";
}
return cell;
}
break;
case 1: {
MyCellType2 *cell = (MyCellType2 *)[tableView dequeueReusableCellWithIdentifier:@"CellType2" forIndexPath:indexPath];
cell.image1.image = [UIImage imageNamed:@"3"];
cell.image2.image = [UIImage imageNamed:@"4"];
return cell;
}
case 2: {
MyCellType3 *cell = (MyCellType3 *)[tableView dequeueReusableCellWithIdentifier:@"CellType3" forIndexPath:indexPath];
cell.lblName.text = @"New Row";
return cell;
}
default:
break;
}
return nil;
}


Related Topics



Leave a reply



Submit