1

我的代码有一点小问题。当我尝试在我的应用程序中有两个页面视图控制器时,我不断收到以下消息。两者都被用于不同的事情。我复制并粘贴了我实现的第一个页面控制器的代码,然后更改了名称以防止冲突。我最近开始收到此错误消息,现在我的程序无法运行。谁能告诉我为什么会这样?

我还收到一个错误,指出协议中的方法“pageViewController:viewControllerBeforeViewController:”未实现。我不太确定这是否是一个相关问题,但有人知道我为什么会得到这个吗?

#import "StorageViewController.h"
#import "InstructionContentViewController.h"

@interface StorageViewController ()

@end

@implementation StorageViewController


- (void)viewDidLoad
{
        [super viewDidLoad];
        // Create the data model
        _pageInstructTitles = @[@"Over 200 Tips and Tricks", @"Discover Hidden Features", @"Bookmark Favorite Tip", @"Free Regular Update"];
        _pageInstructImages = @[@"instructions1.png", @"instructions2.png", @"instructions3.png", @"instructions4.png"];

        // Create page view controller
        self.instructViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InstructionViewController"];
        self.instructViewController.dataSource = self;

        InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
        NSArray *viewInstructControllers = @[startingInstructViewController];
        [self.instructViewController setViewControllers:viewInstructControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

        // Change the size of page view controller
        self.instructViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);

        [self addChildViewController:_instructViewController];
        [self.view addSubview:_instructViewController.view];
        [self.instructViewController didMoveToParentViewController:self];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)startInstructWalkthrough:(id)sender {

    InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
    NSArray *viewControllers = @[startingInstructViewController];
    [self.instructViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}


#pragma mark - Page View Controller Data Source Methods:

- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerBeforeViewController:(UIViewController *)viewInstructController
{
    NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;

    if ((index == 0) || (index == NSNotFound)) {
        return nil;
    }

    index--;
    return [self viewControllerAtIndex:index];
}


- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerAfterViewController:(UIViewController *)viewInstructController
{
    NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;

    if (index == NSNotFound) {
        return nil;
    }

    index++;
    if (index == [self.pageInstructTitles count]) {
        return nil;
    }
    return [self viewControllerAtIndex:index];
}

- (InstructionContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
    if (([self.pageInstructTitles count] == 0) || (index >= [self.pageInstructTitles count])) {
        return nil;
    }

    // Create a new view controller and pass suitable data.
    InstructionContentViewController *instructionContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"InstructionContentViewController"];
    instructionContentViewController.instructImageFile = self.pageInstructImages[index];
    instructionContentViewController.instructTitleText = self.pageInstructTitles[index];
    instructionContentViewController.instructPageIndex = index;

    return instructionContentViewController;


}

- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)instructViewController
{
    return [self.pageInstructTitles count];
}

- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)instructViewController
{
    return 0;
}



@end

像这样的事情是我的想法。我估计命令行参数 10 18 在我的机器上的运行时间不到 8 小时。

public class Search {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);
        int m = Integer.parseInt(args[1]);
        int row = search(n, m);
        if (row >= 0) {
            printRow(m, row);
        }
    }

    private static int search(int n, int m) {
        if (n < 0 || m < n || m >= 31 || powOverflows(m + 1, n)) {
            throw new IllegalArgumentException();
        }
        long[] column = new long[m];
        long[] sums = new long[1 << m];
        int row = 1 << m;
        while (row-- > 0) {
            System.err.println(row);
            for (int j = 0; j < m; j++) {
                column[j] = 0;
                for (int i = 0; i < n; i++) {
                    column[j] = (column[j] * (m + 1)) + ((row >> ((i + j) % m)) & 1);
                }
            }
            for (int subset = 0; subset < (1 << m); subset++) {
                long sum = 0;
                for (int j = 0; j < m; j++) {
                    if (((subset >> j) & 1) == 1) {
                        sum += column[j];
                    }
                }
                sums[subset] = sum;
            }
            java.util.Arrays.sort(sums);
            boolean duplicate = false;
            for (int k = 1; k < (1 << m); k++) {
                if (sums[k - 1] == sums[k]) {
                    duplicate = true;
                    break;
                }
            }
            if (!duplicate) {
                break;
            }
        }
        return row;
    }

    private static boolean powOverflows(long b, int e) {
        if (b <= 0 || e < 0) {
            throw new IllegalArgumentException();
        }
        if (e == 0) {
            return false;
        }
        long max = Long.MAX_VALUE;
        while (e > 1) {
            if (b > Integer.MAX_VALUE) {
                return true;
            }
            if ((e & 1) == 1) {
                max /= b;
            }
            b *= b;
            e >>= 1;
        }
        return b > max;
    }

    private static void printRow(int m, int row) {
        for (int j = 0; j < m; j++) {
            System.out.print((row >> j) & 1);
        }
        System.out.println();
    }
}
4

0 回答 0