我想通过解析添加一些不可编辑的文本(它在我的应用程序中的玩具的一些描述),我坚持使用代码。
这部分(我认为)我应该改变,但不知道如何。
由于 我已经这样了 - (void)retrieveFromParse {
PFQuery *retrieveColors = [PFQuery queryWithClassName:@"Hracky1"]; [retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { colorsArray= [[NSArray alloc] initWithArray:objects]; } [colorsTable reloadData]; }]; [self.colorsTable reloadData]; [self.refreshControl endRefreshing]; }
这完全是TableViewcontroller.m
#import "TableViewController.h" #import "CustomCell.h" @interface TableViewController (){ } @end @implementation TableViewController @synthesize colorsTable; - (void) retrieveFromParse { PFQuery *retrieveColors = [PFQuery queryWithClassName:@"Hracky1"]; [retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { if (!error) { colorsArray= [[NSArray alloc] initWithArray:objects]; } [colorsTable reloadData]; }]; [self.colorsTable reloadData]; [self.refreshControl endRefreshing]; } - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self performSelector:@selector(retrieveFromParse)]; UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init]; self.refreshControl = refreshControl; [refreshControl addTarget:self action:@selector(retrieveFromParse)
forControlEvents:UIControlEventValueChanged];
} - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return colorsArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"colorsCell"; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; PFObject *tempObject = [colorsArray objectAtIndex:indexPath.row]; [cell.imageview setFile: [tempObject objectForKey:@"ImageURL"]]; [cell.imageview loadInBackground]; cell.cellTitle.text = [tempObject objectForKey:@"cellTitle"]; cell.cellDescript.text = [tempObject objectForKey:@"cellDescript"]; return cell; } @end
DetailViewController.m
#import "DetailViewController.h" #import "Parse/Parse.h" @interface DetailViewController () @end @implementation DetailViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } -(void)parseview { NSString *showText = _textdescript.text; PFObject *addValues= [PFObject objectWithClassName:@"Hracky1"]; [addValues setObject: showText forKey:@"TextView"]; } - (void)viewDidLoad { [super viewDidLoad]; [self performSelector:@selector(parseview)]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
DetailViewController.h
> #import <UIKit/UIKit.h>
>
> @interface DetailViewController : UIViewController
> <UITextViewDelegate>
>
> @property (nonatomic, strong) IBOutlet UITextView *textdescript; @end
答案 0 :(得分:0)
将属性添加到第二个视图控制器。在准备segue或使用标识符创建实例时设置它。
此代码:
- (void)parseview
{
NSString *showText = _textdescript.text;
PFObject *addValues= [PFObject objectWithClassName:@"Hracky1"];
[addValues setObject: showText forKey:@"TextView"];
}
正在创建一个新的空解析对象并在其中设置一些文本。文本可能是nil或@""
,因为您刚刚在发生这种情况时加载了视图(尽管您可能在XIB中有一些默认文本)。
你应该做的最有可能的事情是从Parse获取一个对象并询问它以获取文本,然后将其设置到视图上:
PFQuery *query = [PFQuery queryWithClassName:@"Hracky1"];
PFObject *object = [query getFirstObject]; // synchronous request, not ideal, look at getFirstObjectInBackgroundWithBlock
_textdescript.text = [object valueForKey:@"TextView"];
假设您在Parse中定义了一个类Hracky1
,并且它有一个名为TextView
的字符串变量。