0

我使用名为 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)
{

};

}

我在情节提要中为 modalviewcontroller 创建了两个标签,并尝试使它们等于 MainViewController 中的标题和用户值,如下所示

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

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

DetailViewController 尝试失败

4

2 回答 2

0

您的标签没有被更新为正确的值,因为该-isEqualToString:方法用于测试两个NSStrings 是否相等,并且它实际上并没有设置任何 NSString 的值。如果你想给一个字符串变量赋值,你可以像赋值任何其他变量一样做。因此,为了正确设置标签,您只需要分配UILabels 的 text 属性,如下所示:

self.username.text = self.user;
self.captiontext.text = self.caption;
于 2013-08-31T20:10:45.650 回答
0

您是否在 viewDidLoad 方法中的 ModalViewController 中设置了用户名和标题文本?从情节提要初始化后,所有 IBOutlets 都为零,您需要在 viewDidLoad 中进行设置。

- (void)viewDidLoad 
{
   [super viewDidLoad];

   self.username.text = self.user;
   self.captiontext.text = self.caption;
}
于 2013-09-01T11:42:20.360 回答