-2

I am writing an app that is transferring data from one class to another. For some reason the text is not being displayed on the other view when it is supposed to.

My code:

.h Master class:

#import <UIKit/UIKit.h>

@class SSWSettings;

@interface SSWSelectProgram : UITableViewController

@property (strong, nonatomic) SSWSettings *detailViewController;

@property (weak, nonatomic) IBOutlet UILabel *p1;

@end

.m master class:

#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 detail class

#import <UIKit/UIKit.h>

@interface SSWSettings : UITableViewController <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) id detailItem;
@property (weak, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

@end

.m detail class #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];
}
4

1 に答える 1

-1

オブジェクト「detailItem」のタイプは id です。

したがって、NSObject から継承せず、

[self.detailItem description];

call 何も返しません。

試す

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

もちろん、より良い解決策は、タイプ「id」を使用せずに NSString を使用することです

于 2013-09-26T21:23:11.413 に答える