如何从故事板中获取UITextView文本

时间:2014-09-29 08:50:01

标签: objective-c storyboard uitextview nib

我有一个viewController,它有一个用于iPad的xib和用于iPhone的故事板,我知道这很糟糕。但我以前的开发人员就是这样做的。此应用程序使用后台线程来提取或发送聊天消息。我已成功合并发送功能。

现在,我的问题是,每当程序收到聊天时,它从Nib获取viewController对象,而在storyboard中创建的textView for iPhone返回(null)。我试图使用storyBoard对象获取textView但没有结果。请帮忙。

目前我已经做到了这一点

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
                    conferenceViewController *conference=(conferenceViewController *)[storyboard instantiateViewControllerWithIdentifier:@"conference"];

                    NSLog(@"conference :%@",conference);

                    conference.receivedMessage = [NSString stringWithCString:chat->message encoding:NSASCIIStringEncoding];
                    conference.senderDisplayName = [NSString stringWithCString:chat->displayName encoding:NSASCIIStringEncoding];



                    NSLog(@"chatwindow:%@",conference.chatWindow);
                    NSLog(@"chatwindow text:%@", [conference.chatWindow text]);

                    dispatch_async(dispatch_get_main_queue(), ^{


                    if ([conference.lastPerson isEqualToString:conference.senderDisplayName]) {
                        [conference.chatWindow setText:[conference.chatWindow.text stringByAppendingString:[NSString stringWithFormat:@"\n%@",conference.receivedMessage]]];
                    } else {
                        [conference.chatWindow setText:[conference.chatWindow.text stringByAppendingString:[NSString stringWithFormat:@"\n%@: \n%@",conference.senderDisplayName,conference.receivedMessage]]];
                    }

                    conference.lastPerson = conference.senderDisplayName;
                    [conference.chatWindow scrollRangeToVisible:NSMakeRange([conference.chatWindow.text length], 0)];
                });

0 个答案:

没有答案