如何在ios中显示视图中的数组内容

时间:2014-02-14 15:55:29

标签: ios user-interface storyboard

如何在视图中显示数组的内容?

在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];
}

}

我想在ShowContentViewController

中显示showContentVC.contentList

1 个答案:

答案 0 :(得分:2)

ShowContentViewController中,可能在viewDidLoad中,创建一个循环遍历contentList数组的循环。

对于数组中的每个项目,创建一个标签。设置frame[self.view addSubview:...];。增加框架y位置的变量,使下一个标签低于当前标签。在标签上设置一些文字。