我正在编写一个将数据从一个类传输到另一个类的应用程序。出于某种原因,文本未应该显示在另一个视图上。
我的代码:
.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&#34; SSWSettings.h&#34; #import&#34; SSWSelectProgram.h&#34;
@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];
}
答案 0 :(得分:-1)
您的对象“detailItem”的类型为id。
因此,它不会从NSObject和
继承[self.detailItem description];
电话不会返回任何内容。
尝试
self.detailDescriptionLabel.text = (NSString*) self.detailItem;
更好的解决方案当然是不使用类型'id'并使用NSString