Cargar nueva vista con datos, no reemplaza NSString

After tap some row in UITableView apps goes to new screen. I can replace e.g. the image in UIImageView in this screen, while opening, but I defined there also NSString which cannot be replaced. Don't know why. This NSString is just defined in file .h of screenView class as NSString with @property(nonatomic,retain).

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{

[self.navigationController pushViewController:self.screenView animated:YES];

self.screenView.title = @"Screen Name";
self.screenView.imageView.image = MyImage; // this work
self.screenView.MyString = @"Work?"; // but this not
}

Why it doesn't want to attribute a new value for NSString, while the image can be replaced this way?

preguntado el 10 de marzo de 12 a las 09:03

Does the compiler give you an error (and in that case, what is the error?) or is it some kind of runtime problem? -

No. There's no error. Just when I call NSLog with string value in screenView class, it displays (null). -

Could you show the related definition/synthesize and NSLog line? -

In ScreenView h. : @interface ScreenView : UIViewController { IBOutlet UIImageView *imageView; NSString *MyString; } @property(nonatomic,retain) IBOutlet UIImageView *imageView; @property(nonatomic,retain) NSString *MyString; and NSLog(@"%@", MyString); I have MyString synthesized of course. Obviously class ScreenView is load as an object screenView in class for UITableView. As I said it works for picture. -

OK I see why it was not working. I have called the NSLog in vievDidLoad, so it displayed me a default value (not yet replaced). I needed to call it in viewDidAppear to display this right one - changed. -

2 Respuestas

In which method do you log MyString?

I assume you are doing this when the view is being shown or loaded, which means that the it will not contain a value since you are setting it after the push.

I would suggest to try:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{
    self.screenView.title = @"Screen Name";
    self.screenView.imageView.image = MyImage; // this work
    self.screenView.MyString = @"Work?"; // but this not

    [self.navigationController pushViewController:self.screenView animated:YES];
}

respondido 10 mar '12, 09:03

Correct. It was that. I discovered it until you wrote, but thanks :) I loved MyString in viewDidLoad, so the data was not replaced yet. It should be loved in viewDidAppear. - Konrad Kolasa

Prueba

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath    *)indexPath
{

[self.navigationController pushViewController:self.screenView animated:YES];

self.screenView.title = @"Screen Name";
self.screenView.imageView.image = MyImage; // this work
self.screenView.MyString = [[NSString alloc]initWithString:@"Work?"];
//self.screenView.MyString = @"Work?"; // but this not
}

respondido 10 mar '12, 09:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.