我的问题 - 我想在DetailView中传递来自TableView的信息,但是在self.detailViewController.detailItem的某个地方没有传递任何值。
那是:
self.detailViewController.detailItem =@"123";
NSString *sss = self.detailViewController.detailItem;
NSLog(@"%@", sss);
在 NSLog 输出中(空)
这是我的源代码:
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
@property id detailItem;
@property id TitleOfDetail;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@end
DetailViewController.m
#import "DetailViewController.h"
@interface DetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
- (void)configureView;
@end
@implementation DetailViewController
#pragma mark - Managing the detail item
-(void)setTitleOfDetail:(id)newTitleOfDetail {
NSLog(@"123");
if (_TitleOfDetail != newTitleOfDetail) {
_TitleOfDetail = newTitleOfDetail;
// Update the view.
[self configureView];
}
}
-(void)setDetailItem:(id)newDetailItem
{
NSLog(@"123");
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
self.title = self.TitleOfDetail;
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
NSLog(@"1%@", self.TitleOfDetail);
NSLog(@"2%@", [self.detailItem description]);
if (self.TitleOfDetail) {
self.title = self.TitleOfDetail;
}
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
}
…
我的班级
@class DetailViewController;
@interface myclass : UITableViewController
@property DetailViewController *detailViewController;
@end
我的班级
#import "choiseAvtoController.h"
#import "DetailViewController.h"
@interface myclass ()
@end
@implementation myclass
@synthesize detailViewController;
…
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.detailViewController.detailItem =@"123";
NSString *sss = self.detailViewController.detailItem;
NSLog(@"%@", sss);
}
问题可能是什么以及如何解决?
附言对不起我的英语,我只是在学习))
由于您使用的是情节提要,因此您应该在 segue 上打开细节控制器。
在故事板中查找 segue 标识符(例如,它是OpenDetail
),然后将以下代码添加到初始控制器:
-(void)prepareForSegue:(UIStoryboardPopoverSegue*)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"OpenDetail"]) {
DetailViewController *dest = segue.destinationViewController;
dest.detailItem =@"123";
}
}