Reputation: 1229
I am working with a framework that has some delegate methods I'd like to extend/modify.
I apologize for using the framework-specific language, but my problem isn't with the framework - its with the concepts of protocols and delegation.
I have a very shallow understanding of how this is working, so it's fine if you ignore the framework and just help me with the bigger picture.
My class header implements the following protocols:
class ConversationListViewController: ATLConversationListViewController,
ATLConversationListViewControllerDelegate, ATLConversationListViewControllerDataSource,
LYRQueryControllerDelegate {...}
In the ATLConversationListViewController source file, there exists this function:
- (void)configureCell:(UITableViewCell<ATLConversationPresenting> *)conversationCell atIndexPath:(NSIndexPath *)indexPath
{
LYRConversation *conversation = [self.queryController objectAtIndexPath:indexPath];
[conversationCell presentConversation:conversation];
if (self.displaysAvatarItem) {
if ([self.dataSource respondsToSelector:@selector(conversationListViewController:avatarItemForConversation:)]) {
id<ATLAvatarItem> avatarItem = [self.dataSource conversationListViewController:self avatarItemForConversation:conversation];
[conversationCell updateWithAvatarItem:avatarItem];
} else {
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Conversation View Delegate must return an object conforming to the `ATLAvatarItem` protocol." userInfo:nil];
}
}
//other conditions for various other delegate methods
}
I am able to implement this avatarItemForConversation function in my ConversationListViewController class like so:
func conversationListViewController(conversationListViewController:
ATLConversationListViewController!, avatarItemForConversation
conversation: LYRConversation!) -> ATLAvatarItem! {
//implementation goes here
return user as? ATLParticipant
}
My problem is that I need access to the particular UITableViewCell (which implements the ATLConversationPresenting protocol) when I set my avatar - otherwise I have to download the avatar image from my database synchronously because I can't explicitly mention each cell with the default parameters of the delegate function.
So my question is simply this: How can I extend the information available in the delegate function?
In my case, I can work with a reference to a UITableViewCell or the indexPath of the current conversation. I just need a way to associate a conversation with the cell it belongs to.
Upvotes: 0
Views: 284
Reputation: 8153
I have Also working on Layer+Atlas Framework. I have a solutions
For ATLParticipant...
class ConversationParticipant: ConversationAvatarItem, ATLParticipant {
var firstName: String!
var lastName: String!
var fullName: String!
var participantIdentifier: String!
override init() {
super.init()
}
}
For ATLAvatarItem...
class ConversationAvatarItem: NSObject, ATLAvatarItem {
var avatarImageURL: NSURL!
var avatarImage: UIImage!
var avatarInitials: String!
override init() {
super.init()
}
}
How to use
func conversationListViewController(conversationListViewController: ATLConversationListViewController!, avatarItemForConversation conversation: LYRConversation!) -> ATLAvatarItem! {
let lastUser = ConversationAvatarItem()
lastUser.avatarImage = UIImage(named: "ee.png")
return lastUser
}
Upvotes: 1