0

I can't seem to get a UITextView to display a string, in this case the combined variable.

Here is my code:

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
    NSData *pongReply = [@"PONG :hades.arpa\r\n" dataUsingEncoding:NSASCIIStringEncoding];
    NSData *strData = [data subdataWithRange:NSMakeRange(0, [data length])];
    NSString *msg = [[NSString alloc] initWithData:strData encoding:NSASCIIStringEncoding];
    [asyncSocket readDataWithTimeout:-1 tag:0];
    NSLog(@"%@", msg);

    //ping reply
    NSRange pingReply = [msg rangeOfString:@"PING :hades.arpa"];
    NSRange chanMsgs = [msg rangeOfString:@"PRIVMSG #"];
    if (pingReply.location != NSNotFound) {
        NSLog(@"we got pinged");
        [asyncSocket writeData:pongReply withTimeout:-1 tag:1];
    }

    //Channel control / msgs
    if (chanMsgs.location != NSNotFound) {
        NSLog(@"CHANNEL MESSAGE!");
        //code for getting text after (space):
        NSString *str = msg;
        NSString *search = @" :";
        //code for before !~
        NSString *str2 = msg;
        NSString *search2 = @"!";
        NSString *sub = [str substringFromIndex:NSMaxRange([str rangeOfString:search])];
        NSString *sub2 = [str2 substringToIndex:NSMaxRange([str2 rangeOfString:search2])];

        NSString *sub2out = [sub2 stringByReplacingOccurrencesOfString:@":" withString:@""];
        NSString *sub2out2 = [sub2out stringByReplacingOccurrencesOfString:@"!" withString:@""];
        NSString *combined = [NSString stringWithFormat:@"%@: %@", sub2out2, sub];
        NSLog(@"%@", combined);
        chatWindow.text = [chatWindow.text stringByAppendingString:combined];
        chatWindow.text = [NSString stringWithFormat: @"%@", combined];
    }
}

Any ideas of what could be wrong?

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
sploit_
  • 11
  • 4
  • Without more information it's very tough to speculate. What's the value of `chatWindow` at time of execution? What thread is this executing from? (i.e. did you set the socket delegate queue to be the main queue or no?) Are you able to change the text in other parts of the code? – Carl Veazey Jul 15 '13 at 02:11
  • I am unable to change the text in any other part of code, I have even tried to replace the textview with a label and i still could not get this to work :/ – sploit_ Jul 15 '13 at 02:26
  • socket delegate queue is also set as main queue – sploit_ Jul 15 '13 at 02:26

1 Answers1

0

The problem is with chatWindow - either:

  • It is nil
  • It is not bound to a UITextView (as its 'window' name implies)
  • It is not visible (location is outside of the window or hidden is YES)

Check those.

A simple test would be to replace the entire computation that you've listed with:

chatWindow.text = @"Sample chat text";

When that fails look in detail at chatWindow (in the debugger or with NSLog (@"Window: %@", chatWindow))

GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • It seems to be bound correctly IBOutlet UITextView *chatWindow; it is visible for sure, hidden is NO – sploit_ Jul 15 '13 at 02:35
  • That looks like the declaration (at compile time) what is the value at run time? – GoZoner Jul 15 '13 at 02:49
  • seems when i do NSLOG(@:window %@", chatWindow) im receiving null ;/ – sploit_ Jul 15 '13 at 03:23
  • Exactly. If you are using Xcode, place a UITextView in the enclosing view and then drag the connection. Please accept my answer (and upvote when you can). – GoZoner Jul 15 '13 at 03:26
  • I am using Xcode, I created a UITextView and dragged connection to my .h file creating IBOutlet UITextView *chatWindow; still no go :( – sploit_ Jul 15 '13 at 03:31
  • You need to ask another question with the details of your connections. This question is answered. – GoZoner Jul 15 '13 at 04:19