UILabel详细视图未填充

时间:2014-01-24 09:49:26

标签: objective-c cocoa-touch uitableview uiviewcontroller

我有一个UITableView,其中填充了从SQLite数据库收集的数据数组。选择单元格时,将加载与该单元格相关的详细视图。导航控制器上的标题更改正常,但详细视图上的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相同。

1 个答案:

答案 0 :(得分: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];