NSArray数据到UITableView和UICollectionView

时间:2013-07-02 01:08:35

标签: ipad uitableview nsmutablearray singleton uipopovercontroller

我有一个NSMutableArray,我使用以下代码构建

//Question Array Setup and Alloc
    stratToolsDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:countButton,@"count",camerButton,@"camera",videoButton,@"video",textButton,@"text",probeButton,@"probe", nil];
    stratTools = [[NSMutableArray alloc] initWithObjects:@"Tools",stratToolsDict, nil];
    stratObjectsDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratTools,@"Strat1",stratTools,@"Strat2",stratTools,@"Strat3",stratTools,@"Strat4", nil];
    stratObjects = [[NSMutableArray alloc]initWithObjects:@"Strategies:",stratObjectsDict,nil];
    QuestionDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:stratObjects,@"Question 1?",stratObjects,@"Question 2?",stratObjects,@"Question 3?",stratObjects,@"Question 4?",stratObjects,@"Question 5?", nil];


    //add strategys to questions
    for (int i = 0; i < 1; i++) {
        //Send Var to STVar
        [[STVars myMutableArray]addObject:QuestionDict];
    }

For循环中,您将看到“[STVars myMutableArray]”这是用于存储问题数组的单例方法。

我的问题在于我有一个UIPopOverController,它有一个UITableView,需要能够加载所有问题标题..... ex(@“Question 1”,@“Question 2”)。 然后应将它们填充为UIPopOverController中UITableView的数据源。

同样在我初始化问题数组的类中,还有一个UICollectionView,它还需要从UIPopOverController单击的问题数据中获取问题数组中的所有策略。

这是UIPopOverController访问具有Data的Singleton数组。 当我附加数组并尝试加载单元格时,我得到一个“SIGABRT”错误.....(讨厌那个。)

- (id)initWithStyle:(UITableViewStyle)style
{
    if ([super initWithStyle:style] != nil) {

        //Log test
        NSLog(@"QuestionList init method from STVars: %@",[STVars myMutableArray]);
        QuestionsList = [STVars myMutableArray];

你可以看到我首先检查NSLog以确保数据在Singleton类的Array中。然后我将数组分配给另一个NSMutableArray * QuestionsList。

当我将它分配给UITableView时,它永远不会出现。

调整UIPopOvercontroller的大小:

//Make row selections persist.
        self.clearsSelectionOnViewWillAppear = NO;

        //Calculate how tall the view should be by multiplying
        //the individual row height by the total number of rows.
        NSInteger rowsCount = [QuestionsList count];
        NSInteger singleRowHeight = [self.tableView.delegate tableView:self.tableView
                                               heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
        NSInteger totalRowsHeight = rowsCount * singleRowHeight;

        //Calculate how wide the view should be by finding how
        //wide each string is expected to be
        CGFloat largestLabelWidth = 0;
        for (NSString *questionName in QuestionsList) {
            //Checks size of text using the default font for UITableViewCell's textLabel.
            CGSize labelSize = [questionName sizeWithFont:[UIFont boldSystemFontOfSize:20.0f]];
            if (labelSize.width > largestLabelWidth) {
                largestLabelWidth = labelSize.width;
            }
        }

        //Add a little padding to the width
        CGFloat popoverWidth = largestLabelWidth + 100;

        //Set the property to tell the popover container how big this view will be.
        self.contentSizeForViewInPopover = CGSizeMake(popoverWidth, totalRowsHeight);

表格单元代码:

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

    // Configure the cell...
    cell.textLabel.text = [QuestionsList objectAtIndex:indexPath.row];

    return cell;
}

我似乎无法让这些Cell填充Array中的任何问题。 一个很好的简单解释,为什么它可能没有出现将是非常好的。 我已经开发了几天,并认为它可能是简单但不能抓住它......任何帮助都非常感谢!

0 个答案:

没有答案