Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8355379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:50:36+00:00 2026-06-09T09:50:36+00:00

I am trying to take an array that I loaded from another viewer and

  • 0

I am trying to take an array that I loaded from another viewer and put it into a UITableView, not a TableViewController. I don’t know how I would do this. Right now I have this code:

CRHCommentSection.m

#import "CRHCommentSection.h"
#import "CRHViewControllerScript.h"

@interface CRHCommentSection ()

@end

@implementation CRHCommentSection
@synthesize observationTable;

NSArray *myArray; 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}


- (void)viewDidLoad
    {


    myArray = [CRHViewControllerScript theArray];
    NSLog(@"%@", myArray);
    //NSArray* paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0   inSection:1]];
    //[observationTable insertRowsAtIndexPaths:paths   withRowAnimation:UITableViewRowAnimationTop];


    [super viewDidLoad];
    // Do any additional setup after loading the view.

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.

    NSLog(@" in method 1");
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    NSLog(@" in method 2");
   // Return the number of rows in the section.
   return [myArray count];


   }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath {

    NSLog(@" in method 3");

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [myArray objectAtIndex:indexPath.row];    
    return cell;
}

CRHCommentSection.h

    #import <UIKit/UIKit.h>


@interface CRHCommentSection : UIViewController

@property (weak, nonatomic) IBOutlet UITableView *observationTable;



@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T09:50:37+00:00Added an answer on June 9, 2026 at 9:50 am

    Since you have posted this same example code more than once, Ill give you the way to do this without using statics. And Yes you do need to set the collection (array) on the view controller not the UITableView as the tableView uses the controller as a datasource.

    Lets say you had a UITableView that displayed search results… And you launch this view controller from either some other view or from the application delegate like so..

    In your viewController (yours is CRHCommentSection) define a property for the array you are going to populate the table with.

    @property (nonatomic,retain, setter=setSearchResults:) NSArray *searchResults; //use your array name here
    //BTW please dont call it ARRAY..its confusing.
    

    Also in your commentsController (which would be a better name that what you have) add the setter for
    the array

    -(void) setSearchResults:(NSArray *)searchResults
    {
        //in case we loaded this view with results previously release the previous results
        if ( _searchResults )
        {
            [_searchResults release];
        }
        _searchResults = [searchResults retain]; 
    
       [_tableView reloadData];
    }
    

    When you instantiate the new view controller with the UITableView in it – set the “array”,
    in your case comments in my case searchResults

    _searchResultsViewController = [[SearchResultsViewController alloc] initWithNibName:@"SearchResultsViewController" bundle:nil];
    
    //now set the array on the controller
    _searchResultsViewController.searchResults = mySearchResults; //(your array)
    

    Thats a simple way to communicate the array for the table view when you instantiate a view controller.

    Also the naming conventions will help you clear things up

    If you have a view controller for comments it should be

    CommentsViewController

    And the array if it contains comments should be called comments – for readability.

    Cheers.

    As for the rest of the boilerplate setting the datasource and delegate and cellForRow etc,
    you got that advice on the last go around so I wont repeat it here.

    @bigkm had a good point

    @interface SearchResultsViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
    

    Your view controller has to be defined properly as above with the protocols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to take the entire post array and put each value into
Im trying to create a method that take 2 int array as the input
I am trying to take a string of text and create an array from
I am trying to take an array that contains 400 integers, and split it
Ok I am trying to take a string and put it into the intent
hi guys im trying to take the value of data(0) and put it into
I am trying to take a flat array and recreate it so that it's
I'm trying to create a custom JSP tag that would take an array object
I am trying to take the data that is returned to me from a
I am trying to find a way to take an array of keywords that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.