質問

I'm working through the CS193p Stanford iOS course and am nearly done with Assignment 3 - in which I convert the graphing calculator to a universal app for iPad as well. The app draws a graph when a program (e.g. "x + 3") is entered into the calculator and then the user presses a Graph button. On the iPhone, I simply segued when the Graph button was pressed, but in the iPad, I have a UISplitViewController that I set up a target action from the Graph button:

- (IBAction)ipadGraphPressed:(UIButton *)sender {
    if ([self splitViewGraphViewController]) {
        [[self.splitViewController.viewControllers lastObject] setProgram:self.brain.program];
    }
}

This calls setProgram: in the GraphViewController, which then calls setNeedsDisplay: on the GraphView and should draw the graph.

For comparison, here is the segue method that works on iPhone:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [segue.destinationViewController setProgram:self.brain.program];
}

I am very sure that the connection is established between the button and its action method, but when I run the app, this action method never gets called when the button is pressed. Is there anything else to check for to ensure the method gets called?

役に立ちましたか?

解決 2

It turns out there was nothing wrong with my code, per se. After fiddling with the storyboard, I noticed that even if I added new buttons to the master view, they never showed up when the application launched. I tried changing the name of the storyboard from iPad.storyboard to iPad_1.storyboard, and then my changes showed up, but none of my rotation code was in effect. My solution to this whole mess was to backtrack to a previous version of the app right before I added the new storyboard. I re-added an iPad storyboard and was able to make all the correct connections.

To confirm this, a friend of mine checked out the project on Github and reported that while I was not able to call the IBAction method, it worked perfectly fine for him. I believe there was something messed up with my local storyboard settings, and this was preventing the application from working correctly. My takeaway from this is to be careful with naming and renaming storyboard files, especially when dealing with version control.

他のヒント

I had the same problem. I connected everything properly on my IBOutlets and IBActions. What's causing the problem is a transparent view on top of the buttons that's blocking the touches.

After I resized the view so that it won't block the buttons underneath it, it solved my problem.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top