how do i create a custom viewController for each table cell in objective-c

so i have been banging my head aginast my keybaord trying to figure this out. how do i create a custom viewController with a textView for each table cell and save the textView to the certain view in objective-c.

Accepted Reply

"custom viewController....for each table cell"


Do you want to do this within the cell or do you want to do this when the cell is selected.


If you want to do this 'within each cell' - I don't understand the question, please explain what you want the table to look like.


But if you want to do this when a cell is selected then place code in didSelectRowAtIndexPath: that creates ('instantiates') a viewController for that particular cell:


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row]==0){
        MyEvents *theEvents=[[MyEvents alloc] init];  //  this creates a viewController because row 0 was selected
        [theEvents forMessages];  // this will run forMessages within MyEvents
        [self.navigationController pushViewController:theEvents animated:YES];// or you could present the view controller
        
    }else{   //   other rows, different view controllers.Th

//then in the viewController itself (i.e. MyEvents) you have code that creates the textView in viewDidLoad like:
    theMessageView=[[UITextView alloc] initWithFrame:CGRectMake(10, topCorrection +90 +spacing*1.5, width-20,height- topCorrection-120-spacing*5.5) textContainer:nil];
    [self.view addSubview:theMessageView];
    theMessageView.font=[UIFont systemFontOfSize:16];
    theMessageView.textAlignment=NSTextAlignmentLeft;
    theMessageView.editable=NO;
    theMessageView.dataDetectorTypes=UIDataDetectorTypeLink;
    theMessageView.textColor=[UIColor whiteColor];
    theMessageView.backgroundColor=darkGreen;
 

and the viewController itself, MyEvents is a .m and .h file that can be accessed by this viewController because you have added

#import "MyEvents.h"

at the very top of the .m file.

Replies

"custom viewController....for each table cell"


Do you want to do this within the cell or do you want to do this when the cell is selected.


If you want to do this 'within each cell' - I don't understand the question, please explain what you want the table to look like.


But if you want to do this when a cell is selected then place code in didSelectRowAtIndexPath: that creates ('instantiates') a viewController for that particular cell:


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row]==0){
        MyEvents *theEvents=[[MyEvents alloc] init];  //  this creates a viewController because row 0 was selected
        [theEvents forMessages];  // this will run forMessages within MyEvents
        [self.navigationController pushViewController:theEvents animated:YES];// or you could present the view controller
        
    }else{   //   other rows, different view controllers.Th

//then in the viewController itself (i.e. MyEvents) you have code that creates the textView in viewDidLoad like:
    theMessageView=[[UITextView alloc] initWithFrame:CGRectMake(10, topCorrection +90 +spacing*1.5, width-20,height- topCorrection-120-spacing*5.5) textContainer:nil];
    [self.view addSubview:theMessageView];
    theMessageView.font=[UIFont systemFontOfSize:16];
    theMessageView.textAlignment=NSTextAlignmentLeft;
    theMessageView.editable=NO;
    theMessageView.dataDetectorTypes=UIDataDetectorTypeLink;
    theMessageView.textColor=[UIColor whiteColor];
    theMessageView.backgroundColor=darkGreen;
 

and the viewController itself, MyEvents is a .m and .h file that can be accessed by this viewController because you have added

#import "MyEvents.h"

at the very top of the .m file.