-1

我有一个带有一些名称的 TableView。我想在另一个 ViewController 上显示这些名称,但我不明白。

这是我的代码:

AnguckenViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath {


UIViewController *DetailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];


AnguckenViewController *DetailKey = [self.originalsource objectAtIndex:[tableView indexPathForSelectedRow].row];

const char *cPlainKey = [DetailKey cStringUsingEncoding:NSASCIIStringEncoding];

NSString *plistPath;
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                          NSUserDomainMask, YES) objectAtIndex:0];



NSString *pszDetailValueString = [NSString stringWithFormat:@"%s",szSafeKey];

NSString *szDetailValue = [temp objectForKey:pszDetailValueString];



[DetailViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:DetailViewController animated:YES completion:^(void){}];

}

DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController {
    IBOutlet UIButton *BackButton;
    NSString *_pszKey;
    NSString *_pszValue;
}
@property (nonatomic, retain) NSString *pszKey;
@property (nonatomic, retain) NSString *pszValue;

@property (retain, nonatomic) IBOutlet UILabel *keyLabel;
@property (retain, nonatomic) IBOutlet UILabel *valueLabel;


@end

细节视图控制器.m

@implementation DetailViewController
@synthesize pszKey;
@synthesize pszValue;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
        _keyLabel.text = _pszKey;
}
4

2 回答 2

0

在模态显示之前,您需要设置视图控制器的 pszKey 属性,例如 DetailViewController。

DetailViewController.pszKey = @"The value";
[DetailViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:DetailViewController animated:YES completion:^(void){}];

而且在 viewDidLoad 中,最好使用属性的 getter,而不是直接访问实例变量:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.keyLabel.text = self.pszKey;
}
于 2013-05-23T09:06:28.620 回答
0

所以最后它起作用了,

我改变了这一行:

 UIViewController *DetailViewController = [self.storyboard     instantiateViewControllerWithIdentifier:@"DetailViewController"];

至:

DetailViewController *DetailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

谢谢

于 2013-05-23T10:25:08.667 回答