2013-08-31 63 views
0

使用自定義的ModalViewController調用MZFormSheetController來顯示UICollectionView的Detail View。在模態視圖控制器目前我已經創建性能如這些:DetailViewController以編程方式iOS

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

我嘗試當用戶點按UICollectionViewCell這樣來設定細節視圖控制器的顯示: - (無效)的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]; 

然而在此之後所有的模態視圖控制器的標籤仍然說標籤這樣的..

Failed Attempt at DetailViewController

回答

0

您的標籤沒有被更新到正確的值,因爲使用了-isEqualToString:方法來測試兩個NSString是否相等,並且它沒有實際設置任何NSString的值。如果你想給一個字符串變量賦值,你可以像分配任何其他變量一樣來完成。因此,爲了正確地設置標籤,你只需要在UILabel S的文本屬性分配,就像這樣:

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

2013年8月31日23:48:00.962 Floadt [1363:C07] - [的UILabel isEqualToString:]:無法識別的選擇發送到實例0xba809c0 2013年8月31日23:48:00.963 Floadt [1363: c07] ***終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [UILabel isEqualToString:]:無法識別的選擇器發送到實例0xba809c0' – Prad

+0

我得到了那個錯誤^^^ – Prad

+0

@ prnk28這意味着你打電話標籤上的'isEqualToString:'。你可能想看看[類的引用](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/對於'isEqualToString:',instm/NSString/isEqualToString :)。 – shearnonsense

0

你設置的用戶名和captiontext在viewDidLoad方法你ModalViewController裏面?在故事板初始化之後,所有IBOutlet都是零,您需要在viewDidLoad內部進行設置。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

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

是的,我已經把它放在viewDidLoad方法中 – Prad