0

我有一个使用以下代码构建的 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(@“问题 1”,@“问题 2”)。然后应该将它们填充为 UIPopOverController 中 UITableView 的数据源。

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

这是访问具有数据的单例数组的 UIPopOverController。当我附加阵列并尝试加载单元格时,我收到“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 类的数组中。然后我将数组分配给另一个 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;
}

我似乎无法让这些单元格填充数组中的任何问题。关于为什么它可能没有出现的一个很好的简单解释会非常好。我已经连续开发了几天,并认为它可能很简单,但无法抓住它......非常感谢任何帮助!

4

0 回答 0