Usando UIReferenceLibraryViewController de Cocos2d (2.0)

Been struggling with this all day for some reason, hoping someone can shed some light on it.

He configurado un CCLabelTTF and added a touch handler for it, on touch end I want to look up the string value of that label in the UIReferenceLibraryViewController. Here's what my attempt looks like (My game is in landscape mode which is why I'm attempting the 90degree rotation):

if(NSClassFromString(@"UIReferenceLibraryViewController")) {

                if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:word.Value] == YES)
                     UIReferenceLibraryViewController *reference =
                    [[UIReferenceLibraryViewController alloc] initWithTerm:word.Value];
           = CGPointMake(winSize.width/2, winSize.height/2);
                    reference.view.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90.0f));

                    [[[CCDirector sharedDirector] view] addSubview:reference.view];

Este planteamiento de « tipo de works. I click my label, the UIReferenceLibraryViewController is shown (though it isn't rotated in landscape for some reason), and my definition shows up. When I click the "done" button in the UIReferenceLibraryViewController, however, my app crashes with an EXEC_BAD_ACCESS. Figure I'm missing something obvious here, but not sure what.

Any help is appreicated, of course.

Muchas Gracias

preguntado el 02 de septiembre de 12 a las 20:09

1 Respuestas

I had a similar problem. In my case, I was declaring and instantiating the UIReferenceLibraryViewController object inside a method in my class. I received an error when selecting the 'Done' button as my UIReferenceLibraryViewController object no longer existed at that point. To solve the problem, I created a member variable within the class interface:

UIReferenceLibraryViewController *reference;

I then created a property with retain:

@property (retain) UIReferenceLibraryViewController *reference;

In the method when I wanted to present the dictionary screen in did used the following:

reference = [[UIReferenceLibraryViewController alloc] initWithTerm:cell.textLabel.text];
[[[CCDirector sharedDirector] openGLView] addSubview:reference.view];

I then released the reference object in the dealloc method. Unfortunately, it no longer crashes but the 'Done' button does nothing now.

Información adicional: Ultimately I have my application working. My app adds a UITableView over a CCScene and allows the user to click a table view cell in order to look up the definition of the word within the cell.

In order to get this working I did the following: Within my CCScene class (Game.m), I create a UITableView. I then create a UITableViewController class and set the UITableView dataSource and delegate to that new class.

myTableView.dataSource = myWordListViewController;
myTableView.delegate = myWordListViewController;

I then add the UITableView as a subview of the CCScene as follows;

[[[CCDirector sharedDirector] openGLView] addSubview:myTableView];

The CCScene class has a member variable (called delegate) that is an instance of my AppDelegate class. The AppDelegate class has a member variable that is an instance of the RootViewController.

RootViewController  *viewController;

So, now I have a UITableView presented to the user (on top of the CCScene). This table view contains a list of words. I now need to ensure the table view cells present the dictionary definition when clicked.

In my MyWordListViewController (UITableViewController) I ensure that the methods exist to allow this class to act as a data source and delegate for my table view.

<UITableViewDelegate, UITableViewDataSource>

Also, when the user clicks a cell in the UITableView (that is a subview of CCSCENE), I want the dictionary to appear on top of the table view.

I am responding to the user click in the didSelectRowAtIndexPath method of MyWordListViewController. Since I added the table view as a subview of the CCScene (Game.m), I need to use the AppDelegate RootViewController that my CCScene is relying upon.

To do this, I added a member variable to MyWordListViewController that holds an instance of the AppDelegate class.

delegate = (AppDelegate*) [[UIApplication sharedApplication] delegate];

Now in the didSelectRowAtIndexPath method of MyWordListViewController, I can display the dictionary over the table view by relying upon the RootViewController variable within the AppDelegate class.

reference = [[UIReferenceLibraryViewController alloc] initWithTerm:cell.textLabel.text];

[delegate.viewController presentModalViewController:reference animated:YES];

It may not be the most eloquent solution but it works.

Respondido 13 Oct 12, 21:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.