我正在编写一个将数据从一个类传输到另一个类的应用程序。由于某种原因,文本没有显示在其他视图上。
我的代码:
.h 大师班:
#import <UIKit/UIKit.h>
@class SSWSettings;
@interface SSWSelectProgram : UITableViewController
@property (strong, nonatomic) SSWSettings *detailViewController;
@property (weak, nonatomic) IBOutlet UILabel *p1;
@end
.m 大师班:
#import "SSWSelectProgram.h"
#import "SSWSettings.h"
@interface SSWSelectProgram ()
@end
@implementation SSWSelectProgram
@synthesize p1;
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cellChosen = [self.tableView cellForRowAtIndexPath:indexPath];
if (cellChosen == static1) {
self.detailViewController.detailItem = p1.text;
[self dismissViewControllerAnimated:YES completion:NULL];
}
.h 详细信息类
#import <UIKit/UIKit.h>
@interface SSWSettings : UITableViewController <UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;
@end
.m 详细类 #import "SSWSettings.h" #import "SSWSelectProgram.h"
@interface SSWSettings ()
-(void)configureView;
@end
@implementation SSWSettings
@synthesize detailDescriptionLabel;
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[self configureView];
}