Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set the subclass of a TableView that was created programatically? (no storyboards)
    primarykey
    data
    text
    <p>So I am using a custom framework and I need to set the subclass of my 'TableView' and 'TableViewCell' to the custom framework. I would normally do this easily with the identity inspector but since I created everything programmatically, I do not know how to do it. I am also not using storyboards. Any tips?</p> <p>---edit----</p> <p>TableViewController.h </p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "Tasks.h" #import "Properties2ViewController.h" #import "PKRevealController.h" #import "FMMoveTableView.h" #import "FMMoveTableViewCell.h" #import "DetailViewController.h" @interface ToDoTableViewController : UITableViewController &lt;Properties2ViewControllerDelegate, UITableViewDelegate, FMMoveTableViewDataSource&gt; @property (strong, nonatomic) NSMutableArray *taskArray; -(IBAction)addCell:(id)sender; @end </code></pre> <p>TableViewController.m</p> <pre><code>#import "ToDoTableViewController.h" @implementation ToDoTableViewController @synthesize taskArray; - (id)init { self = [super initWithStyle:UITableViewStyleGrouped]; if (self) { UINavigationItem *i = [self navigationItem]; [i setTitle:@"Task List"]; [[i title] uppercaseString]; UIBarButtonItem *bbi = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addCell:)]; [[self navigationItem] setRightBarButtonItem:bbi]; [self.tableView setSeparatorColor:[UIColor colorWithRed:26.0/255 green:188.0/255 blue:156.0/255 alpha:1.0f]]; [self.tableView setBackgroundView:nil]; [self.tableView setBackgroundColor:[UIColor colorWithRed:26.0/255 green:188.0/255 blue:156.0/255 alpha:1.0f]]; } return self; } - (id) initWithStyle:(UITableViewStyle)style{ return [self init]; } -(void) viewDidLoad{ FMMoveTableView *mtc = [[FMMoveTableView alloc]init]; [mtc setDataSource:self]; [self.tableView setDelegate:self]; taskArray = [[NSMutableArray alloc] init]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; if (!cell) cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"UITableViewCell"]; NSString *detailText = [NSString stringWithFormat:@"%.0f", [[taskArray objectAtIndex:[indexPath row]] timeInterval]]; [[cell textLabel] setText:[[taskArray objectAtIndex:[indexPath row]] taskName]]; cell.textLabel.text = [[[taskArray objectAtIndex:[indexPath row]] taskName] uppercaseString]; [[cell textLabel] setFont:[UIFont fontWithName:@"AvenirNext-DemiBold" size:15]]; [cell setBackgroundColor:[UIColor colorWithRed:236.0/255 green:240.0/255 blue:241.0/255 alpha:1.0f]]; cell.textLabel.textColor = [UIColor colorWithRed:26.0/255 green:188.0/255 blue:156.0/255 alpha:1.0f]; [[cell detailTextLabel] setText:detailText]; [[cell detailTextLabel] setFont:[UIFont fontWithName:@"Avenir-Black" size:16]]; return cell; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [taskArray count]; } -(IBAction)addCell:(id)sender{ Properties2ViewController *pvc = [[Properties2ViewController alloc]init]; [pvc setDelegate:self]; [self presentViewController:pvc animated:YES completion:NULL]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [[self tableView] reloadData]; } -(void)properties2ViewControllerDidEnterPropertiesSuccesfully:(Tasks *)t{ if (![[t taskName] isEqual: @""]) { [taskArray addObject:t]; } [self.tableView reloadData]; } -(void)moveTableView:(FMMoveTableView *)tableView moveRowFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{ [tableView moveRowAtIndexPath:fromIndexPath toIndexPath:toIndexPath]; [tableView reloadData]; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ Tasks *task = [taskArray objectAtIndex:[indexPath row]]; DetailViewController *dvc = [[DetailViewController alloc]init]; [dvc setTestTask:task]; [[self navigationController] pushViewController:dvc animated:YES]; // PKRevealController *pkrc = [[PKRevealController alloc]initWithFrontViewController:self rightViewController:dvc options:nil]; //[pkrc showViewController:dvc animated:YES completion:NULL]; } -(void)loadView{ [super loadView]; } @end </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.
    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