开发者

How to change the iVar of another class

This is the code. It is pretty straight forward. I made 开发者_StackOverflowtwo classes one is returning the error and hydrate the iVar of another class (TheView) and show it to the User. however I cant figure it out why the View return Null at all time. Thanks is advance guys.

     @interface AccountControllerModel : NSObject {
            NSString *anError;
        }
        @property (nonatomic, retain) NSString *anError;

AccountControllerModel.m
    @synthesize anError;

    - (void)uploadFailed:(ASIHTTPRequest *)theRequest{

RegistrationViewController *regoVC = [[RegistrationViewController alloc] init];
[regoVC manageTheError:@"THIS IS AN ERROR"];
[regoVC release]; regoVC = nil;
    }

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    @interface RegistrationViewController : UIViewController {
        NSMutableString *test;
    }
    @property (nonatomic, assign) NSMutableString *test;

@synthesize test;

-(void)viewDidLoad {
  test = [[NSMutableString alloc] init];
}
-(void)manageTheError:(NSString *)theError{
self.test = [NSMutableString stringWithFormat:@"%@",theError];
resultOfRegistration.text = [NSString stringWithFormat:@"%@",self.test];
NSLog(@"test is %@",self.resultOfRegistration.text); //It comes back Null
 }


Alex is right, some clarification on what's not working would help but by looking through I may have found your error. [[NSNotificationCenter defaultCenter] postNotificationName:@"Blah" object:self], you have object set to nil which could be your issue with the notification.


There are a number of problems with your code.

@property (nonatomic, assign) NSMutableString *test;

Two things here, one, exposing a NSMutable* object in a property is never a good idea, two you should 'copy' value objects, especially because this is how you're treating it in your code. Make this @property (nonatomic, copy) NSString *test;

regoVC.test = [NSMutableString stringWithString:self.anError];

You're assigning an autoreleased object to an assign property, this is a leak, the change above will fix that.

NSLog(@"test is %@",test); // It is perfect as you expect

test isn't in scope here, but I'd assume that was supposed to be regoVC.test, these other changes should remedy the situation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜