Reputation: 10245
I have almost finished working my way through this tutorial here Its really informative and has helped me understand how protocols and delegates work together for passing data around.
However I have one warning that poping up when I try to tell my subview that the mainview is its delegate. its sending back this warning
"+setDelegate:' not found (return type defaults to 'id')"
Everything was on track up till that point and I am just woundering what this error means and if it is anything to do with the way I have implemented my code.
below is where the warning is happening...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
//--- Idendify selected indexPath (section/row)
if (indexPath.section == 0) {
//--- Get the subview ready for use
VehicleResultViewController *vehicleResultViewController = [[VehicleResultViewController alloc] initWithNibName:@"VehicleResultViewController" bundle:nil];
// ...
//--- Sets the back button for the new view that loads
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:vehicleResultViewController animated:YES];
[VehicleResultViewController setDelegate:self]; //<<-- warning here says -->> Method'+setDelegate:' not found (return type defaults to 'id')
switch (indexPath.row)
{
case 0: vehicleResultViewController.title = @"Manufacture";
[vehicleResultViewController setRequestString:@"manufacture.php"]; //sets the request string in searchResultsViewController
break;
//...
Any help would be greatly appreciated.
Updated, this is how I set my delegate up SecondView.h
//...
@interface VehicleResultViewController : UITableViewController <NSXMLParserDelegate> {
//..
id <PassSearchData> delegate;
}
//..
@property (retain) id delegate;
@end
SecondView.m
//..
@synthesize delegate;
//..
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[self delegate] setVehicleSearchFields:vehicleCellTextLabel];
}
//..
I hope this better clarifies what I am doing.
Upvotes: 0
Views: 1203
Reputation: 14694
You are calling an instance method on a class.
This line:
[VehicleResultViewController setDelegate:self];
should be:
[vehicleResultViewController setDelegate:self];
The first line calls setDelegate on VehicleResultViewController, which is the name of the class. Since setDelegate is not a class method the compiler complains.
The corrected line calls setDelegate on vehicleResultViewController, which is an instance of the class that you allocated. This will work because setDelegate is an instance method.
Upvotes: 3
Reputation: 30846
It seems that you have declared a setter for delegate
as a class method, indicated by the +
in the warning.
I'm guessing you have this declared somewhere...
+ (void)setDelegate:(id <SomeProtocol>)aDelegate
when it should be - (void)setDelegate:(id <SomeProtocol>)aDelegate
Upvotes: 1