我正在創建segue以便將數據從tableview控制器傳遞到詳細視圖控制器as shown in the picture。我的表單元格 有一個UIImage和兩個UILabel,我想在其中詳細顯示三個視圖控制器。但是,當我運行該程序,它看起來像this空。從tableview控制器傳遞數據到視圖控制器,但它顯示爲空
這裏是tableviewcontroller.m
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"prepareForSegue:%@", segue.identifier);
if([segue.identifier isEqualToString:@"TeamMembersSegue"]){
NSIndexPath*indexPath = (NSIndexPath*)sender;
ViewController2*vc = ((UINavigationController*)segue.destinationViewController).topViewController;
vc.lawfirmname = [tableData objectAtIndex:indexPath.row];
vc.detail= [detail objectAtIndex:indexPath.row];
vc.lawyerimage = [thumbnails objectAtIndex:indexPath.row];
}
}
的SEGUE和detailviewcontroller.h的代碼(視圖控制器2)
#import <UIKit/UIKit.h>
@interface ViewController2 : UIViewController
@property (nonatomic, strong) NSString *lawfirmname;
@property (strong, nonatomic) IBOutlet UILabel *lawfirm;
@property (nonatomic, strong) NSString *detail;
@property (weak, nonatomic) IBOutlet UITextView *detailtextview;
@property (nonatomic, strong) UIImage*lawyerimage;
@property (weak, nonatomic) IBOutlet UIImageView *image;
@end
和detailviewcontroller.m(視圖控制器2)
#import "ViewController2.h"
@interface ViewController2()
@end
@implementation ViewController2
@synthesize lawfirmname;
@synthesize lawfirm;
@synthesize detail;
@synthesize detailtextview;
@synthesize lawyerimage;
@synthesize image;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.lawfirm.text = self.lawfirmname;
self.detailtextview.text = self.detail;
self.image.image = self.lawyerimage;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
如果有人有任何解決方法,我將不勝感激。如果你不明白這個問題,請告訴我。
你是否檢查vc.lawfirmname和其他屬性是否在yuor prepareForSegue中設置? –
您確定segue的目的地是導航控制器嗎? – vadian
您可能想要確保您在prepareForSegue中使用選定的行 –