Julia
Julia

Reputation: 171

How to display contents of array in view in ios

How do you display the contents of an array in a view?

In HomeViewController.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *indexPath = self.tableView.indexPathForSelectedRow;

Show *show = [self.shows objectAtIndex:indexPath.section];
ShowContentItem *showItem = show.showContentItems[indexPath.row];

if( [segue.identifier isEqualToString: @"Headline_Section"] ) {        
    HeadlinesViewController *headlinesVC = (HeadlinesViewController *)segue.destinationViewController;
    headlinesVC.shows = [[NSMutableArray alloc] initWithObjects:show, nil];
} else {
    NSInteger contentIndex = [self.storyPostContent indexOfObject:showItem];
    NSRange rangeForView = NSMakeRange(contentIndex, [self.storyPostContent count] - contentIndex );

    ShowContentViewController *showContentVC = (ShowContentViewController *)segue.destinationViewController;
    showContentVC.contentList = [self.storyPostContent subarrayWithRange: rangeForView];
}

}

I want to display showContentVC.contentList in ShowContentViewController

Upvotes: 0

Views: 56

Answers (1)

Wain
Wain

Reputation: 119031

In ShowContentViewController, probably in viewDidLoad, create a loop which iterates over the contentList array.

For each item in the array, create a label. Set the frame and [self.view addSubview:...];. Increment a variable for the y position of the frame so the next label is below the current one. Set some text on the label.

Upvotes: 2

Related Questions