UITableView无法渲染

时间:2013-12-17 09:32:58

标签: ios iphone objective-c cocoa-touch uitableview

所以我有一个UITableView作为界面构建器中另一个视图的子视图,它没有渲染。我已经检查过section方法的数量返回1,并且section方法中的行数返回一个数字> 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是否链接到连接管理器中的文件所有者。

为什么没有调用draw方法?

这是我的.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

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

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*

3 个答案:

答案 0 :(得分:2)

您必须在

中创建单元格
-(UITableViewCell *)tableView:(UITableView *)tableView
        cellForRowAtIndexPath:(NSIndexPath *)indexPath

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

将其修改为与此类似的内容:

-(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;
}

答案 1 :(得分:0)

我遇到了同样的问题,所提供的示例都没有用,所以我推出了一个简单的延迟函数。

class func delay(delay:Double, closure:()->()) {
    dispatch_after(
        dispatch_time(
            DISPATCH_TIME_NOW,
            Int64(delay * Double(NSEC_PER_SEC))
        ),
        dispatch_get_main_queue(), closure)
    }
}}

func renderCategories () {

    Utils.delay(1) {
        self.tableView.reloadData()
    }
}

答案 2 :(得分:-1)

经过大量的工作 - 这很有效 -

我检查了使用autolayout进行表格视图(之前已经取消选中,我猜是因为这个视图存在于滚动视图中,我已经取消选中了autolayout)。然后画了 - 我不明白为什么。

相关问题