Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control a customized UITableViewCell within a UITableView Implemented within a UIViewController?
    primarykey
    data
    text
    <p>In my app I wish to have a <strong>UIViewController</strong> that will hold a <strong>UITableView</strong> in it. In this UITableView I wish to have a <strong>customized UITableViewCell</strong> (i.e. I wish to define my own elements in this CELL - image, labels and buttons - as seen in the image below). And... I want to create them in the Storyboard.</p> <ul> <li>Now, setting the elements in the Storyboard is easy.</li> <li>I understand how to connect the UITableView and set it in the UIViewController (including the delegates in the .h file and using the basic table delegate methods).</li> <li>What I'm not clear about, is how to connect and control the customized UITableViewCell and its outlets. Can I create the Outlets and Actions within the <strong>UIViewController</strong> .h and .m files? Do I need to create a separated <strong>UITableViewCell.h/.m</strong> files and call on them in the cellForRowAtIndexPath method? </li> </ul> <p>Can anyone suggest what's the best approach for my needs?</p> <p><img src="https://i.stack.imgur.com/vlq1a.png" alt="enter image description here"></p> <p><strong>UPDATE</strong>: Here is the code I used in <strong>cellForRowAtIndexPath</strong> while using the separated <strong>MyCell.h/m</strong> file option. This code is written in the <strong>ViewController.m</strong> file, where the UITableView is implemented.</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ContentCell"; MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //MyCell is the Objective-C Class I created to manage the table cells attributes. //@"ContentCell" is what I had entered in the Storyboard&gt;&gt;UITableViewCell as the Cell Identifier. if (cell == nil) { cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; //Here is the place I'm not clear about - Am I supposed to init the cell in a different way? If so, how? } cell.contentNameLabel.text = [self.dataArray objectAtIndex: [indexPath row]]; // this is the test I had done to check if the new "MyCell" object is actually getting what I would expect it to get. well... the text gets updated in the relevant label, so i guess it gets it return cell; } </code></pre> <p>When running the app, using the debugger break point, I can see that the code always skips the "if (cell == nil)" and never enters the code where the new MyCell object supposes to be allocated and initiated. Any idea what may I be doing wrong?</p>
    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.
    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