parse.com을 사용하고 있습니다. 나는 의견을 표시하려고하지만 난 내 DetailViewController에서 PFObject를 얻을 수있는 의견을 얻기 위하여 그러나 여기다른 클래스의 메서드를 호출하면 반환되지 않습니다.
모든 코드 편집
CommentsViewController
에 PFObject을 반환하지 않는거야. 당신이place
객체를 할당 어디 아마 내가 볼 수없는 바보 같은
CommentsView 컨트롤러
#import "CommentsViewController.h"
#import "DetailViewController.h"
#import "CommentsCell.h"
@interface CommentsViewController(){
NSArray *commentsArray;
id commentInstance;
}
@end
@implementation CommentsViewController
- (id)init {
if (self = [super init]) {
[self performSelector:@selector(commentsQuery)];
}
return self;
}
- (void)commentsQuery {
commentInstance = [[DetailViewController alloc] init];
PFObject *tempObj = [commentInstance placeObject];
PFQuery *query1 = [PFQuery queryWithClassName:@"activity"];
[query1 whereKey:@"type" equalTo:@"comment"];
[query1 whereKey:@"place" equalTo:[NSString stringWithFormat:@"%@", [tempObj objectId]]];
NSLog(@"%@", tempObj);
[query1 orderByDescending:@"createdAt"];
[query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error){
commentsArray = [[NSArray alloc]initWithArray:objects];
NSLog(@"%lu", (unsigned long)[commentsArray count]);
}
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *CellIdentifier = @"Cell";
CommentsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[CommentsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
PFObject *placeObj = [commentInstance placeObject];
cell.username.text = @"test";
return cell;
}
@end
DetailsViewCOntroller
#import "DetailViewController.h"
#import "CommentsViewController.h"
@interface DetailViewController(){
CommentsViewController *test;
}
@end
@implementation DetailViewController
@synthesize place;
@synthesize userPhoto, message, username, checkCount, photo, scroller, commentsTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
test = [[CommentsViewController alloc] init];
self.commentsTableView.delegate = test;
self.commentsTableView.dataSource = test;
//Adjust the message label box height
CGSize textSize = [[place objectForKey:@"message"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(201, CGFLOAT_MAX) lineBreakMode: NSLineBreakByWordWrapping];
userPhoto.file = [place objectForKey:@"thumbnail"];
[userPhoto loadInBackground];
username.text = [place objectForKey:@"username"];
message.text = [place objectForKey:@"message"];
checkCount.text = [NSString stringWithFormat:@"%@", [place objectForKey:@"checkMarkCount"]];
[message sizeToFit];
if ([place objectForKey:@"photo"] != Nil){
photo.file = [place objectForKey:@"photo"];
[photo loadInBackground];
//[photo sizeToFit];
photo.frame = CGRectMake(6, textSize.height + 50, photo.frame.size.width, photo.frame.size.height);
float sizeOfContent = 0;
UIView *lLast = [scroller.subviews lastObject];
NSInteger wd = lLast.frame.origin.y;
NSInteger ht = lLast.frame.size.height;
NSLog(@"%@", lLast);
sizeOfContent = wd+ht;
scroller.contentSize = CGSizeMake(scroller.frame.size.width, sizeOfContent+100);
}
else{
float sizeOfContent = 0;
UIView *lLast = [scroller.subviews lastObject];
NSInteger wd = lLast.frame.origin.y;
NSInteger ht = lLast.frame.size.height;
NSLog(@"%@", lLast);
sizeOfContent = wd+ht;
scroller.contentSize = CGSizeMake(scroller.frame.size.width, sizeOfContent+100);
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)checkMarkButton:(UIButton *)sender {
}
- (PFObject *)placeObject{
return place;
}
@end
'DetailViewController :: init' 기능이 있습니까? 그것은 무엇을합니까? 'placeObject' 함수는 중복되어'property place'를 복제합니다. 당신은 또한'place '지시자를 필요로하지 않는다. 컴파일러는 그것을 암묵적으로한다. – dmitri