iOS:上传到parse.com时的NSString显示空白 [英] iOS: NSString when uploaded to parse.com shows blank

查看:86
本文介绍了iOS:上传到parse.com时的NSString显示空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个NSString从一个类带到另一个类,以保存在parse.com上

I have taken an NSString from one class to another to be saved on parse.com

我有一个测验视图控制器,其中用户在UITextView中输入问题,然后他们按下一步转到选择朋友视图控制器,在这里他们选择用户,然后通过解析发送问题.

I have a quiz view controller where a user enters a question in a UITextView and then they press next to go to the select friends view controller where they select a user and then send the question over parse.

quiz.h

@property (nonatomic,strong) IBOutlet UITextView *textField;
@property (nonatomic, strong)  NSString *text;


quiz.m
- (void)viewDidLoad {
    [super viewDidLoad];

    UITextView *textView = [[UITextView alloc] init];
    NSString *text = self.textField.text;
    selectFriendsViewController *sfvc = [[selectFriendsViewController alloc] init];
    sfvc.string = text;
}

- (IBAction)next:(id)sender {

if ([text length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!"
                                                            message:@"Enter some text"
                                                           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    } else {

    }

}

selectfriendsviewcontroller.h

@property (nonatomic, strong)  NSString *string;

selectfriendsviewcontroller.m

- (void)viewDidLoad {
[super viewDidLoad];

quizViewController *qvc = [[quizViewController alloc] init];
qvc.text = string;
UITextView *textfield = [[UITextView alloc] init];
string = textfield.text;
 NSLog(@"%@", self.string);
}

如果我在viewdidload方法中的selectfriends.m文件中删除了NSLog以外的所有内容,则该文件将不会上传以进行解析.并且我得到显示的alertView和错误,提示不存在文件或目录.

if i remove everything except the NSLog in the selectfriends.m file in viewdidload method, the file wont upload to parse. and i get the alertView showing and error saying not file or directory exists.

然后我上传到parse.com

then i upload to parse.com

- (void) uploadMessage;
{
NSString *text =string;
NSString *fileType= @"text";
NSString * fileName= @"text.txt";

NSData *data = [text dataUsingEncoding:NSUTF8StringEncoding];

PFFile *file = [PFFile fileWithName:fileName data:data];

[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (error) {
       UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please try sending your message again" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

       [alertView show];

1)字符串不作为null传递,因为null在运行时未在控制台中显示. (即使使用NSLog语句,控制台中也没有显示任何内容)

1) the string does not pass as null as null does not show in the console at runtime. (nothing shows in the console even with the NSLog statement)

2)该文件作为text.txt文件上传到parse.com,但是当我下载该文件以检查文本时,文件为空.

2) the file uploads to parse.com as a text.txt file but when i download the file to check the text the file is blank.

因此,在quizVC中键入一个问题,然后按下一步转到selectfirendsVC,然后选择朋友并上传到parse.com

So in quizVC type a question then press next to go to selectfirendsVC then select friends and upload to parse.com

我如何上传文本文件以在quizVC的UITextView中显示用户输入的文本?

how can i upload the textfile to show the user inputted text in the UITextView in the quizVC?

推荐答案

您不希望仅与SelectFriends vc的任何实例进行通信,例如在viewDidLoad中创建的实例.您必须与将要呈现的实例进行通信.

You don't want to communicate with just any instance of your SelectFriends vc, like the one created in your viewDidLoad. You must communicate with the instance that is going to be presented.

删除Quiz vc的viewDidLoad中的代码.创建从测验vc到SelectFriends vc的序列.在Quiz vc中,实现prepareForSegue.在该方法中,询问textView的文本并在segue.destinationViewController上设置string属性.那就是将要呈现的那个.

Remove the code in Quiz vc's viewDidLoad. Create a segue from Quiz vc to SelectFriends vc. In Quiz vc, implement prepareForSegue. In that method, interrogate the textView's text and set the string property on the segue.destinationViewController. That's the one that will be presented.

(关于vc-vc通信的更一般的处理方法,此处).

(A more general treatment of vc-vc communication here).

这篇关于iOS:上传到parse.com时的NSString显示空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆