Error tells me that "No '-setRosterForBoat:' method found".
What I am doing is attempting to pass an array backwards through the Navigation Controller stack that i have.
In the viewContoller that I am attempting to pass the array to I have it set up in the .h like so:
NSArray *rosterForBoat;
@property(nonatomic开发者_开发问答, retain) NSArray *rosterForBoat;
But the program runs fine and the array gets set with the proper objects. Should I hate to just ignore this, does anyone have any suggestions?
CoCoachAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSArray *arr = [[NSArray alloc] initWithArray:appDelegate.boatNavController.viewControllers];
[appDelegate.boatNavController popToViewController:[arr objectAtIndex:1] animated:YES];
[[arr objectAtIndex:1] setRosterForBoat:tempRowers];
Since you are using the rosterForBoat
array as property, I would synthesize it and set it the following way:
CoCoachAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSArray *arr = [[NSArray alloc] initWithArray:appDelegate.boatNavController.viewControllers];
ViewController *view_controller = [arr objectAtIndex:1];
[appDelegate.boatNavController popToViewController:view_controller animated:YES];
view_controller.rosterForBoat = tempRowers;
Hope this helps...
The issue is that NSArray doesn't define a type like other language's arrays. So, when you use objectAtIndex:, it comes back at the generic 'id' type.
If you want to make the warning go away, do something like:
YourViewController * controller = [arr objectAtIndex: 1];
[controller setRosterForBoat: tempRowers];
And make sure that you define setRosterForBoat: in your view controller's .h file.
Edit: And to answer your other question: it works because Objective-C uses message passing to communicate between instances. At compile time, XCode can't find Class->Method relationship between 'id' and setRosterForBoat:, but during runtime, because that method happens to exist for your view controller, everything works swimmingly.
精彩评论