UITableView无法呈现 [英] UITableView not rendering

查看:65
本文介绍了UITableView无法呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个UITableView作为界面生成器中另一个视图的子视图,并且未呈现。我已经检查过sections方法的数目是否返回1,section方法中的行数是否返回数字> 0。

So I have a UITableView as a subview of another view in interface builder, and it is not rendering. I've already checked that the number of sections method is returning 1, and that the number of rows in section method is returning a number > 0.

这是我的代码-

    - (void)viewDidLoad{
    //[super viewDidLoad];
    _trendingImageView.image = [UIImage imageNamed:@"trending.png"];
    [self.scrollView setScrollEnabled:YES];
    [self.scrollView setClipsToBounds:YES];
    self.scrollView.delegate = self;

    UINib *nib = [UINib nibWithNibName:@"RecommendationCell"
                                bundle:nil];
    [self.recommendationsTableView registerNib:nib forCellReuseIdentifier: reco

    recommendationCellIdentifier];
        self.recommendationsTableView.scrollEnabled = YES;
    }


-(void)executeRecSearch{
    @try{
        [AJAXUtils getAsyncJsonWithUrl:(NSURL *)[NSURL URLWithString:[NSString stringWithFormat:someUrl]] callback:^(NSDictionary *returnjson){
            if(returnjson != nil){
                self.recommendations = returnjson[@"Node"][@"Recommendations"][@"Components"];
                NSLog(@"COUNT: %d", [self.recommendations count]);
                [self performSelectorOnMainThread:@selector(renderRecommendations) withObject:nil waitUntilDone:YES];
            }

        }];

    } @catch (NSException* e) {

    }
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sections{
    return [self.recommendations count];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

-(void)renderRecommendations{
    self.recommendationsTableView.hidden = FALSE;
    [self.recommendationsTableView reloadData];
}

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"CELL INDEX PATH CALLED: %@", self.recommendations);
    RecommendationCell *cell = [self.recommendationsTableView dequeueReusableCellWithIdentifier:recommendationCellIdentifier];

    if(self.recommendations != nil){
        NSDictionary* recommendationData = self.recommendations[indexPath.row];
    }
    return cell;
}

我还检查了委托和dataSource是否链接到文件的所有者。连接管理器。

I also checked that the delegate and dataSource were linked to the File's Owner in the connections manager.

为什么不调用draw方法?

Why is the draw method not being called?

这是我的.h文件

@interface BasicCardViewController : UIViewController<RateViewDelegate, UIScrollViewDelegate, UITableViewDelegate,UITableViewDataSource>

@property(atomic)NSInteger rating;

@property(copy,nonatomic)NSString *userPageLink;
@property(copy,nonatomic)NSString *nodePage;
@property(strong, nonatomic)NSString* description;
@property(strong,nonatomic)NSString* pageScore;
@property(strong,nonatomic)NSString* pageTitle;
@property(strong,nonatomic)NSString* phoneNumber;
@property(strong,nonatomic)NSString* address;
@property(weak,nonatomic)NSArray* recommendations;
@property(atomic)NSInteger* numberOfRecommendations;


@property (strong, nonatomic) IBOutlet TooviaRateView *rateView;
@property(strong,nonatomic)IBOutlet UIImageView *restaurantImageView;
@property(strong,nonatomic)UIImage* restaurantImage;
@property(strong,nonatomic)IBOutlet UITextView* descriptionView;
@property(strong,nonatomic)IBOutlet UIImageView* trendingImageView;
@property(strong,nonatomic)IBOutlet UILabel* pageScoreLabel;
@property(strong,nonatomic)IBOutlet UILabel* pageTitleLabel;
@property(strong,nonatomic)IBOutlet UIScrollView* scrollView;
@property(strong,nonatomic)IBOutlet UILabel* phoneNumberLabel;
@property(strong,nonatomic)IBOutlet UILabel* addressLabel;
@property(strong,nonatomic)IBOutlet UITableView* recommendationsTableView;

- (IBAction)logOut:(id)sender;
- (IBAction)writeRecommendation:(id)sender;
- (IBAction)call:(id)sender;
-(IBAction)map:(id)sender;

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sections;
@end

这是我打印出数据源和委托时得到的- / p>

This is what I get when I print out data source and delegate-

2013-12-17 17:58:41.473 ReviewApp[17451:a0b] DATA SOURCE : *nil description*
2013-12-17 17:58:41.473 ReviewApp[17451:a0b] Data Delegate : *nil description*


推荐答案

您必须在

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath

dequeueReusableCellWithIdentifier
如果没有可用于退出队列的单元格,将返回nil。

dequeueReusableCellWithIdentifier will return nil if no cell is available to dequeue.

将其修改为类似于以下内容:

Modify it to something similar to this:

-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"CELL INDEX PATH CALLED: %@", self.recommendations);
    RecommendationCell *cell = [self.recommendationsTableView dequeueReusableCellWithIdentifier:recommendationCellIdentifier];

    if(cell==nil){
      cell = [[UITableViewCell alloc]init];
    }

    if(self.recommendations != nil){
        NSDictionary* recommendationData = self.recommendations[indexPath.row];
    }
    return cell;
}

这篇关于UITableView无法呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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