我迷失了塞格。我试图通过this tutorial来完成。
一切正常,但只有一行给我写错误,我不知道如何修复它。 有错误的图片:
TableViewController.h
#import <UIKit/UIKit.h>
#import "Parse/Parse.h"
#import "CustomCell.h"
#import "DetailViewController.h"
@interface TableViewController : UITableViewController <UITableViewDelegate,UISearchDisplayDelegate, UISearchBarDelegate> {
NSArray *colorsArray;
NSArray *searchResults;
}
@property (strong, nonatomic) IBOutlet UITableView *colorsTable;
@property (strong, nonatomic) IBOutlet UISearchBar *searchBar;
@property (strong, nonatomic) IBOutlet UISearchDisplayController *searchBarController;
@end
TableViewController.m
#import "TableViewController.h"
#import "CustomCell.h"
#import "DetailViewController.h"
@interface TableViewController (){
}
@end
@implementation TableViewController
@synthesize colorsTable;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{ if ([segue.identifier isEqualToString:@"displayDetail"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
PFObject *object = [self.objects objectAtIndex:indexPath.row];
UINavigationController *nav = [segue destinationViewController];
DetailViewController *detailViewController = (DetailViewController *) nav.topViewController;
detailViewController.exam = object;
}
}
- (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
DetailedViewController.h
#import <UIKit/UIKit.h> #import "Parse/Parse.h" @interface DetailViewController : UIViewController <UITextViewDelegate> @property (nonatomic, strong) PFObject *exam; @property (nonatomic, strong) IBOutlet UITextView *descriptext; @end
DetailViewcontrolled.m
#import "DetailViewController.h" #import "Parse/Parse.h" #import "TableViewController.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)viewDidLoad { [super viewDidLoad];{ self.descriptext.text = [self.exam objectForKey:@"TextView"]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
答案 0 :(得分:2)
从我从你的代码中读取的内容是因为你使用的是普通的UITableViewController。为了能够访问属性“self.objects”,你必须使用Parse的子类UITableViewController,称为“PFTableViewController”。他们包含了“对象”属性。
我可以推荐本教程来了解PFTableViewController
http://www.appcoda.com/ios-programming-app-backend-parse/
如果您希望它在没有PFTableView的情况下工作,您可以执行以下操作: 我可以看到你有一个名为colorsArray的数组,并且你将Parse对象添加到该数组中。
所以不要这样做:
PFObject * object = [self.objects objectAtIndex:indexPath.row];
你可以这样做:
PFObject * object = [colorsArray objectAtIndex:indexPath.row];
我希望它适合你!
答案 1 :(得分:0)
除了做本教程的另一个答案,也许你不应该通过PFObject本身......
找出并查询您要在详细视图控制器中显示的任何文本,在表视图控制器中检索它,然后只传递它(而不是整个PFObject)。