-2

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!!

kb920
  • 3,039
  • 2
  • 33
  • 44
  • possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](http://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Hot Licks Jul 01 '15 at 11:44
  • 1
    Somewhere in code you are trying to call `setTranscript:` on `UITableViewCell `object: in your `cellForRowAtIndexPath:` maybe? – Rok Jarc Jul 01 '15 at 11:44
  • 3
    Learn how to get the exception stack trace. You're blind without it. – Hot Licks Jul 01 '15 at 11:45

2 Answers2

1

looks like you're calling setter in UITableViewCell, but should call in MessageView. Could you show code used to call "setTranscript"?

1

It seems that you have a custom tableview cell where in which you have written a property Transcript which has a setter setTranscript.

It seems that you dequeueReusableCellWithIdentifier method in cellForRowAtIndexPath is returning UITableViewCell instead of you custom cell.

So try to set an identifier for the cell in the table view and in cellForRowAtIndexPath retrieve the cell with the same identifier.

shoan
  • 1,303
  • 15
  • 22