2014-01-24 140 views
0

我有一个UITableView填充从SQLite数据库收集的数据数组。当选择一个单元格时,将加载一个与该单元格相关的详细视图。导航控制器上的标题更改正常,但详细视图上的UILabel未被填充。UILabel详细视图未被填充

相关tableViewController代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    ExhibitorDetailViewController *exhibitorDetailViewControllerInstance = [[ExhibitorDetailViewController alloc] init]; 

    exhibitorDetailViewControllerInstance.theTitle = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text; 
    exhibitorDetailViewControllerInstance.exhibitorDetailModal = [arrayOfExhibitors objectAtIndex:indexPath.row]; 

    // Have tried setting the text before the detail view is loaded wiht the line below 
    exhibitorDetailViewControllerInstance.LabelExhibitorDescription.text = arrayOfExhibitors.description; 

    [self.navigationController pushViewController:exhibitorDetailViewControllerInstance animated:YES]; 

} 

详细视图控制器的viewDidLoad中事件:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.title = _theTitle; //This sets the title ok 

    NSLog(@"0 - %@", _exhibitorDetailModal.description); //This property is what I want to fill the UILabel with 

    self.LabelExhibitorDescription.text = _exhibitorDetailModal.description; // This does nothing 
    self.view.backgroundColor = [UIColor colorWithRed:0.6 green:0.8 blue:0.8 alpha:2.0f]; // If I don't set the background colour here it loads up black (despite being set in the storyboard) 


    NSLog(@"label text = %@", self.LabelExhibitorDescription.text); // This shows the text box being null despite having its text property set above 

} 

详细视图头文件:

@interface ExhibitorDetailViewController : UIViewController 
{ 

} 
    @property (nonatomic, retain) NSString *theTitle; 
    @property (strong, nonatomic) IBOutlet UILabel *nameLabel; 
    @property (strong, nonatomic) IBOutlet UILabel *categoryLabel; 
    @property (strong, nonatomic) IBOutlet UILabel *descriptionLabel; 
    @property (strong ,nonatomic) NSArray *exhibitorDetailModal; 
    @property (strong, nonatomic) IBOutlet UILabel *LabelExhibitorDescription; 

@end 

为什么不是文本的UILabel被填充?

谢谢。

编辑:

我已经登录阵列的“出射”的说明 - [arrayOfExhibitors objectAtIndex:indexPath.row],并将该显示了正确的数据按预期这是相同的,其示出了_exhibitorDetailModal.description在详细视图中。

+0

如果您在iOS 7上,请尝试上下滚动表格视图,然后查看是否填充了标签。我已经看到了这种行为,但我不知道根本原因。 –

+0

是的,我正在使用Xcode5 - iOS7。 tableView看起来不错,我可以向上/向下滚动它,然后单击单元格加载详细视图 - 然后我可以在nag控制器中点击后退按钮并返回到tableView,这再次确定,允许我单击其他单元格 – Ryan

+0

您是否尝试在'didSelectRowAtIndexPath:'方法中记录'[arrayOfExhibitors objectAtIndex:indexPath.row]'? – GoGreen

回答

0

为了最终得到这个工作,我重写了整个代码并整理了整个过程。

要正确显示UILabel,我首先将exhibitorDetailModal对象的description属性传递给NSString。

_stringExhibitorDescription = _exhibitorDetailModal.description;  

然后我初始化了UILabel。

self.labelExhibitorName = [[UILabel alloc]init]; 

然后设置的UILabel的文本是NSString的上述

[_labelExhibitorName setText:_stringExhibitorName]; 

然后加入作为的UILabel UIView的的子视图。

[self.view addSubview:_labelExhibitorDescription];