2013-09-26 37 views
-2

我在写一个将数据从一个类传输到另一个类的应用程序。出于某种原因,文本在应该显示时不会显示在其他视图上。不在类之间移动的内容?

我的代码:

.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详细类 #i M端口 “SSWSettings.h” #进口 “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]; 
} 
+0

你尝试排除故障呢? –

+0

完成任何调试?这些属性都是非零? – Wain

回答

-1

你的对象 “detailItem” 为ID类型。

因此,它不会从NSObject的继承和

[self.detailItem description]; 

调用不会返回任何东西。

尝试

self.detailDescriptionLabel.text = (NSString*) self.detailItem; 

更好的解决方案,当然,是不使用的类型“ID”和使用NSString

+0

我如何将它变成NSString,因为它不起作用? –

+0

确保它是一个NSString *,它应该工作。如果没有,请提供关于错误的一些细节 – Jack

+0

我没有在Xcode中得到错误,但是当我在模拟器中运行它时,标签中没有任何内容出现。 –