DetailViewController以编程方式iOS

时间:2013-08-31 19:53:58

标签: iphone ios objective-c uicollectionview master-detail

我使用名为MZFormSheetController的自定义ModalViewController来显示UICollectionView的详细信息视图。目前我已在模态视图控制器中创建了属性,例如:

@property (strong,nonatomic) NSString *user;
@property (strong,nonatomic) NSString *caption;
@property (weak, nonatomic) IBOutlet UILabel *username;
@property (weak, nonatomic) IBOutlet UILabel *captiontext;

当用户点击UICollectionViewCell时,我尝试设置详细视图控制器的显示,如下所示: - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];

ModalViewController *m = [self.storyboard instantiateViewControllerWithIdentifier:@"modalView"];
m.entry = [self entries][indexPath.row];
m.text = [self entries][indexPath.row];
m.user = entry[@"user"][@"full_name"];
m.caption = text[@"caption"][@"text"];

MZFormSheetController *formSheet = [[MZFormSheetController alloc] initWithViewController:m];
formSheet.transitionStyle = MZFormSheetTransitionStyleDropDown;
formSheet.shouldDismissOnBackgroundViewTap = YES;
[formSheet presentAnimated:YES completionHandler:^(UIViewController *presentedFSViewController) {

}];
formSheet.didTapOnBackgroundViewCompletionHandler = ^(CGPoint location)
{

};

}

我在storyalviewcontroller的storyboard中创建了两个标签,我尝试使它们等于MainViewController中的标题和用户值,如下所示

[self.username.text isEqualToString:self.user];
[self.captiontext.text isEqualToString:self.caption];

然而,在所有这些之后,模态视图控制器的标签仍然说像这样的标签..

Failed Attempt at DetailViewController

2 个答案:

答案 0 :(得分:0)

您的标签未更新为正确的值,因为-isEqualToString:方法用于测试两个NSString是否相等,并且它实际上并未设置任何NSString的值。如果要为字符串变量赋值,则执行与分配任何其他变量相同的值。因此,为了正确设置标签,您只需要分配UILabel s的text属性,如下所示:

self.username.text = self.user;
self.captiontext.text = self.caption;

答案 1 :(得分:0)

您是否在viewDidLoad方法中的ModalViewController中设置了username和captiontext?在故事板初始化之后,所有IBOutlet都是零,你需要在viewDidLoad中设置。

- (void)viewDidLoad 
{
   [super viewDidLoad];

   self.username.text = self.user;
   self.captiontext.text = self.caption;
}