Thanks to developers from Stack, I was able to spot the origin of my previous problem, which occurs in a different file of my app (I am thus writing a new post).
I am trying to code a chat app for fun and I wrote a custom view class to display all the sent and received messages. I am calling this class in my main view controller using viewWithTag
in the following line of code: MessageView *messageView = (MessageView *)[cell viewWithTag:MESSAGE_VIEW_TAG];
.
The MessageView class has one property called transcript and containing all the information of the message. I also set the transcript property of the MessageView
class in my main view controller. However, I'm having trouble using it in the implementation file for MessageView
.
I am getting the error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setTranscript:]: unrecognized selector sent to instance 0x7fc77afe1070'
, which I don't really understand... Here is my setTranscript method (don't read everything, I assume the error is only coming from the first line).
- (void)setTranscript:(Transcript *)transcript
{
// Set the message text
NSString *messageText = transcript.message;
_messageLabel.text = messageText;
// Compute message size and frames
CGSize labelSize = [MessageView labelSizeForString:messageText fontSize:MESSAGE_FONT_SIZE];
CGSize balloonSize = [MessageView balloonSizeForLabelSize:labelSize];
NSString *nameText = transcript.peerID;
CGSize nameSize = [MessageView labelSizeForString:nameText fontSize:NAME_FONT_SIZE];
// Comput the X,Y origin offsets
CGFloat xOffsetLabel;
CGFloat xOffsetBalloon;
CGFloat yOffset;
if ([transcript.direction isEqualToString:@"right"]) {
// Sent messages appear or right of view
xOffsetLabel = 320 - labelSize.width - (BALLOON_WIDTH_PADDING / 2) - 3;
xOffsetBalloon = 320 - balloonSize.width;
yOffset = BUFFER_WHITE_SPACE / 2;
_nameLabel.text = @"";
// Set text color
_messageLabel.textColor = [UIColor whiteColor];
// Set resizeable image
_balloonView.image = [self.balloonImageRight resizableImageWithCapInsets:_balloonInsetsRight];
}
}
From the alert message I get in the debugger area, I assume that transcript isn't defined correctly in my header (which I was careful to import in the implementation). So here's what my header file looks like:
#import <UIKit/UIKit.h>
#import "Transcript.h"
@class Transcript;
#define MESSAGE_VIEW_TAG (99)
@interface MessageView : UIView
@property (nonatomic, strong) Transcript *transcript;
@end
Does anyone know why I am getting this error message ? What is wrong with my argument, transcript ? Thank you very much by advance!!