"Cannot find protocol declaration for ..." in adopting class objective c - objective-c

I'm a little frustrated at the moment with the custom delegate process in objective-c. I've used the design pattern a few times already and have a pretty good understanding of how it works. I've searched the internet for 2 hours trying to find what I'm doing wrong in this instance, and to no prevail. I also compared my past use of custom delegates that are functioning properly vs. this instance and can't see any conceptual difference. so here we go:
I'm making a custom dual table view (one table for the list, and the other to hold the selections made from that list.) so that the user can make basic selections. here is the header file:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#protocol ListSelectorViewDelegate
-(void) listTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
-(void) selectTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
-(void) listTableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
-(void) selectTableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
- (void)listTableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)selectTableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
#end
#protocol ListSelectorDataSource
-(UITableViewCell *)listTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(UITableViewCell *)selectTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(NSArray *)sectionIndexTitlesForListTableView:(UITableView *)tableView editStatus:(BOOL) status;
-(NSArray *)sectionIndexTitlesForSelectTableView:(UITableView *)tableView editStatus:(BOOL) status;
-(NSInteger)listTableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
-(NSInteger)selectTableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;
#end
#interface ListSelectorViewController : UIViewController {
//Delegate
id <ListSelectorViewDelegate> listsDelegate;
id <ListSelectorDataSource> listsDataSource;
//Titles
IBOutlet UINavigationBar *pageNavBar;
IBOutlet UINavigationBar *selectNavBar;
IBOutlet UINavigationBar *listNavBar;
//Tables
IBOutlet UITableView *selectTable;
IBOutlet UITableView *listTable;
//Table Data
NSMutableArray *listItems;
NSMutableArray *selectItems;
//Search Bars
IBOutlet UISearchBar *selectedSearch;
IBOutlet UISearchBar *listSearch;
BOOL listTableIsSearching;
BOOL selectTableIsSearching;
}
#property(nonatomic,assign) id <ListSelectorViewDelegate> listsDelegate;
#property(nonatomic,assign) id <ListSelectorDataSource> listsDataSource;
-(IBAction) newItem:(id)sender;
-(IBAction) selectAll:(id)sender;
-(IBAction) clearSelections:(id)sender;
#end
Notice the formal protocol declarations. Also note that this, along with the .m file compile fine. When I try to write a class to adopt the protocol I get the error "Cannot find protocol declaration for "ListSelectorDataSoure" ". I get the same message for the "ListSelectorViewDelegate" as well. Here is the .h file for the delegate class:
#import <Foundation/Foundation.h>
#import"ListSelectorViewController.h"
#interface ListSelectorDelegateTemplate : NSObject
<ListSelectorDataSource,ListSelectorViewDelegate>{
}
#end
Note that I am importing the ListSelectorViewController.h where the protocol declarations are found. Also note that when typing " " it does auto complete which means it does see it. Like I said, I've done it this exact way for other objects with no issues and cannot wrap my head around this one ... Any Help at all would be greatly appreciated

Ok figured it out.... extremely stupid answer here...
I originally created the ListSelectorViewController in a separate project and added it to the current project I'm working on... for some reason the .h and .m were not visible to the rest of the project and was the reason for the errors. simply added a new file to the project and copied over the contents of the original class.

Got this problem today too. It is a xcode bug indeed.
my delegate protocol file was modified by git merge confliction, I fixed the confliction, but all my files using this delegate still cannot find this delegate protocol file.
so i delete these two files by reference ,and add them to project again. it worked!

If ListSelectorViewController.h also imports ListSelectorDelegateTemplate.h, you'll get errors like that. You should move any imports that you can into the ".m" file, and replace them with #class declarations if necessary.

Got the same problem today. This seems to be a xcode bug.
Anyway my solution was to create an empty h. file, declare my protocol there, and then #import this new h. file anywhere where i was using it.

You have put my protocol declaration on separate file and import it then

what worked for me was cleaning the project (shift+command+K) simple.

In my case the error was caused by a cyclic #import. The delegate protocol declaration file included the implementor of the delegate . The implementor included the delegate protocol declaration file.

Related

How to programmatically create a UITableView in UIPopover so it responds to -cellForRowAtIndexPath

I have 3 UITableViews in a class; one of the tableViews is programmatically created in a UIPopover where I assign it a tag. In -cellForRowAtIndexPath, I check the tag each tableView and configure the tableView depending on the tag id.
The problem is the popover is not created until after -cellForRowAtIndexPath is called. I don't see how I can have a separate -cellForRowAtIndexPath in the method that creates the tableView in the popover. I have the tableView.dataSource = self in the method that creates the tableView.
How can I point the tableView in the popover to it's own -cellForRowAtIndexPath?
So it wasn't entirely clear, but it seems as though your asking how to assign different cellForRowAtIndexPath for the different TableView's in your class. To this end, I've created this small piece of sample code to illustrate how you could accomplish having differing sets of data sources for multiple UITableView's in a single class.
As you can see, there are three different DataSource objects that can each independently control the cellForRowAtIndexPath for each of the three different UITableView's. There's no reason you can't have two table views utilize a single DataSource, and then the third table use it's own.
*Note: There is no reason to keep all of this in a single file, but if that is your desire you certainly can do that.
//UITableViewOne
#interface DataSourceOne : NSObject <UITableViewDataSource>
#end
#implementation DataSourceOne
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell for TableViewOne
}
#end
//UITableViewTwo
#interface DataSourceTwo : NSObject <UITableViewDataSource>
#end
#implementation DataSourceTwo
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell for TableViewTwo
}
#end
//UITableViewThree
#interface DataSourceThree : NSObject <UITableViewDataSource>
#end
#implementation DataSourceThree
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Setup cell for TableViewThree
}
#end
#interface MultiTableViewController ()
#property (nonatomic,strong) UITableView *tableOne;
#property (nonatomic,strong) UITableView *tableTwo;
#property (nonatomic,strong) UITableView *tableThree;
#property (nonatomic,strong) DataSourceOne *sourceOne;
#property (nonatomic,strong) DataSourceTwo *sourceTwo;
#property (nonatomic,strong) DataSourceThree *sourceThree;
#end
#implementation MultiTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.sourceOne = [DataSourceOne new];
self.sourceTwo = [DataSourceTwo new];
self.sourceThree = [DataSourceThree new];
//Create or Load TableViews from Xib
self.tableOne.dataSource = self.sourceOne;
self.tableTwo.dataSource = self.sourceTwo;
self.tableThree.dataSource = self.sourceThree;
}
Let me know if you want any more clarification, or if you have further questions on the topic.

Accessing NSStrings from other classes

i hope you can help me solving my actual problem:
I´ve set up a new project with a navigation controller. For the table view of the project I´ve added a new class for it, called "TableViewController.h" and "TableViewController.m".
In this class I´ve declared in .h a property for a NSString to access it from other classes, like this:
#property (strong, nonatomic) NSString *testString;
In .m I´ve synthesized it as followed:
#synthesize testString;
Now I set in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath-Method of the table view controller the following:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
testString = #"Hello, World!";
}
Now created a new UIViewController class for the next view which should appear when I´m tapping on a cell (all that works so far). In this UIViewController, called "SecondView" I imported the .h-File of TableViewController.
Further I have this code in SecondView.m:
-(void) viewDidLoad
{
[super viewDidLoad];
TableViewController *demoObject = [TableViewController alloc] init]
NSLog (#"Teststring is: %#" [demoObject.testString]);
}
Now when I start the Simulator I get this Output:
Teststring is: (null)
When I NSLog the testString in TableViewController I get "Hello, World", but why isn´t it "transferred" to the SecondView class and generates the needed output?
You are logging the string in viewDidLoad, which gets called long before it is set in the table views's didSelectRow method. You should also use self.testString = ...
how do you expect the data to 'transfer'? you have to pass it .. in tableView:didSelectCellAt:row (where you push the 2nd view) you have to say:
2ndView.testString = self.testString;

Where should I create NSArray for using as DataSource in my TableView

could anybody explain me: where should I create NSArray (I would like to use it in my ViewController class in DataSourseDelegate's methods).
I tried to create it in init, viewDidLoad, viewWillAppear methods, but or get error or this array is empty.
My controller .h file:
#interface SendingController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *arrDataSource;
}
#property (nonatomic, retain) NSArray *arrDataSource;
Or maybe is there the better way in such situation: I use tableView in Navigation interface, and number of section, it names (I use this Array right here) and rows in section defined value (I need table view only to choose disclosure indicator in row to push new controller in Nav stack). How and where should I predefined names of section etc ?? In DataSourceDeleagte's methods ?
The data source of your table view is actually designed for returns such names. The UITableViewDataSource protocol defines in particular two methods :
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
These methods are optionals, but surely, if you want to display any string either in the section header or in the footer, use them. The UITableViewDataSource protocol is documented here.

Creating Protocol/Delegate in Monotouch

I'm a bit confused with how to create a custom protocol/delegate type in Monotouch.
The obj-c equivalent is
#protocol CellController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath;
#optional
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
#end
Does the implementation have to be an abstract class, an interface or what?
I'm sure its not complicated, I just can't get my head around it. A code example would be helpful, but getting pointed in the right direction will still be extremely helpful
Cheers
R
So what I ended up doing was creating an interface and using that :)

UITableView didSelectRowAtIndexPath method not firing

I placed a TableView on my xib file with the following method
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"FIRED THE EVENT");
}
and it doesn't seem to be firing when I click on a cell in the table. Is there something that I'm missing?
Be sure to include UITableViewDataSource, UITableViewDelegate in your .h file