Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set the same width between custom UITableViewCells and UITableView?
    primarykey
    data
    text
    <p>I created several cells with Interface Builder, and I'm using them to fill a UITableView. In other words, I have 3 classes for 3 different kinds of cell, and an other view which contains a UITableView.</p> <p><strong>- My UITableView containing different kinds of cells :</strong> <img src="https://i.stack.imgur.com/PBe6d.png" alt="enter image description here"></p> <p><strong>Here's my problem :</strong> On the iPhone emulator, it looks great. But on the iPad emulator, <strong>the custom cells width is fixed</strong>. The UITableView width fits to the screen width, so it's good, but the UITableViewCells does not fit to the UITableView. <strong>I want to force the custom UITableViewCells to take the UITableView width.</strong> </p> <p>Is there anything to do in <code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath</code>method, where I instanciate my custom cells ? Or do I have to write a thing like <code>self.fitToParent;</code> in the custom cells header file ?</p> <p><strong><em>EDIT (schema) :</em></strong></p> <p><img src="https://i.stack.imgur.com/O5RDE.png" alt="enter image description here"></p> <p><strong><em>EDIT 2 (cellForRowAtIndexPath method) :</em></strong></p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifierType1 = @"cellType1"; static NSString *cellIdentifierType2 = @"cellType2"; NSString *currentObjectId = [[myTab objectAtIndex:indexPath.row] type]; // Cell type 1 if ([currentObjectId isEqualToString:type1]) { CelluleType1 *celluleType1 = (CelluleType1 *)[tableView dequeueReusableCellWithIdentifier:cellIdentifierType1]; if(celluleType1 == nil) celluleType1 = [[CelluleType1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierType1]; celluleType1.lblAuteur.text = @"Type1"; return celluleType1; } // Cell type 2 else if ([currentObjectId isEqualToString:type2]) { CelluleType2 *celluleType2 = (CelluleType2 *)[tableViewdequeueReusableCellWithIdentifier:cellIdentifierType2]; if(celluleType2 == nil) celluleType2 = [[CelluleType2 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierType2]; celluleType2.lblAuteur.text = @"Type2"; return celluleType2; } else return nil; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload