This is my first post, thx, you’ve been very helpful. But I’m stuck. I tried to implement : xcode init controller with data
when I initialize my controller with the new parameter I get : No visible @interface for ‘VisiteViewController’ declares the selector ‘initWithNibName:bundle:texte:’
in VisiteViewController.m I’ve got :
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil texte:(NSString *)chaine{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;}
and I call it like this:
- (IBAction)goToVisite: (id)sender{
NSLog(@"Button pushed");
VisiteViewController *visiteViewController = [[VisiteViewController alloc] initWithNibName:@"VisiteViewController" bundle:nil texte:@"lkj"];
[self.navigationController pushViewController:visiteViewController animated:YES];
}
Thx for your help
Hi and welcome to StackOverflow!
As @janusfidel mentioned, you need to add the declaration to the header (.h) file.
You did not change a method, you created an entirely new one (that – just coincidentally – has a name that looks a bit like one of the existing methods, but the computer has no concept of that). You now have to announce to everybody using your class that there is a new method whose selector (name, basically) is
initWithNibName:bundle:texte:. This does not overwrite, remove, or otherwise interact with the methodinitWithNibName:bundle:, nor with the methodinitor any other method. The similarity in names is basically just there to give the human reader (i. e. you) a clue as to what those methods do[1].Please do not take this personally, but do yourself a favor and get a good book on programming in Objective-C (or object-oriented programming in general). This will make your first steps a lot easier and faster. The Big Nerd Ranch Guides are an excellent series of books, and I would recommend you to buy iOS Programming: The Big Nerd Ranch Guide as soon as you can.
[1]: Technically, there are some naming guidelines that also give clues to the compiler on how to handle memory management in Objective-C, but going into that would just be confusing for now.