iPhone SDK, передавая строки через представления - PullRequest
0 голосов
/ 19 августа 2011

Я пытаюсь передать строку через два представления в приложении для iPhone. На мой второй взгляд, что я хочу восстановить строку в .h у меня есть:

#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
#import "RootViewController.h"

@interface PromotionViewController : UITableViewController {

    NSString *currentCat;
}

@property (nonatomic, retain) NSString *currentCat;

@end

И в .m у меня есть:

@synthesize currentCat;

Однако в первом контроллере представления, когда я пытаюсь установить эту переменную, я получаю ошибку not found:

PromotionViewController *loadXML = [[PromotionViewController alloc] initWithNibName:@"PromotionViewController" bundle:nil];
        [self.navigationController pushViewController:loadXML animated:YES];
        [PromotionViewController currentCat: @"Test"];

Эта третья строка дает мне: метод класса + currentCat не найден

Что я делаю не так?

Ответы [ 4 ]

1 голос
/ 19 августа 2011

Том, Проблема в вашем коде заключается в том, что вы пытаетесь установить строку, используя статический вызов метода для класса. Это сработало бы, если бы вы реализовали статический метод с именем currentCat:

Не думаю, что ты этого хочешь. Ниже описано, как исправить вашу проблему.

[PromotionViewController currentCat:@"Test"];
//This will not work as it is calling the class itself not an instance of it.

[loadXml setCurrentCat:@"Test"];
//This will work. Keep in mind if you are going to call the objective-c 
//synthesize setting directly you will need to capitalize the first letter 
//of your instance variable name and add "set" to the front as I've done.

//Alternatively in objective-c 2.0 you can also use 
//the setter method with the . notation

loadXml.currentCat = @"Test";
//This will work too
0 голосов
/ 19 августа 2011
PromotionViewController *loadXML = [[PromotionViewController alloc] initWithNibName:@"PromotionViewController" bundle:nil];
[loadXML setCurrentCat: @"Test"];
[self.navigationController pushViewController:loadXML animated:YES];

Это должно сделать это.

0 голосов
/ 19 августа 2011

Вам нужно сделать:

loadXML.currentCat = @"Test";
0 голосов
/ 19 августа 2011

Вам нужно получить строку, подобную этой, поскольку это свойство, а не метод:

NSString* myString = controller.currentCat; // where controller is an instance of PromotionViewController
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...