开发者

iOS reseting reused ViewControllers or issue With ASIHTTPRequest?

I'm new to iOS development, and I'm having a problem with reused view controllers.

My application has a login view and then a view with details of the user, I'm using navigation controller to navigate through them. I login with username1... When I touch the back button on details View I wish to go back to the login vie开发者_StackOverfloww (and this actually happens) if I try to login with username2 it opens the details view of the username1 (couse its kind of reused in the navigation controller`s stack). when i pop a view from the navigation controller's stack it just goes to back and its not deallocated... How can I reset the info of the details view or something like that, or maybe reset the navigation controller's stack?

here I show some code:

self.myVC = [[[myVC alloc] initWithNibName:@"MyVC" bundle:[NSBundle mainBundle]] autorelease];        

[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:self.myVC animated:NO];

Actually, I recently found an issue about the login, its related to the ASIHTTPRequest I'm using. I'm posting my login code so you guys can take a look...

-(IBAction)loginGivenUserName:(NSString *)username andPassword:(NSString *)password{

    NSURL *url = [NSURL URLWithString:@"http://foo.heroku.com/users/login.json"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setUsername:username];
    [request setPassword:password];
    [request setRequestMethod:@"POST"];
    [request setDelegate:self];
    [request startAsynchronous];

}

It works just fine for the first time the user logs in... But when it goes back and try to login again, it responses is code 200 with any parameters passed...

I've debugged already, it passes the parameters right, but the response is wrong, does this HTTPRequest save some kind of cookie?

Because, it grants the access but loads the last user's data...

Again, it works just fine for the first time, if the user put some wrong parameters it blocks the login...


I'm guessing you're doing something like:

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

which, of course, means that you are caching the detail controller in one of your classes. The only way an old view can show up is if YOU give the old view to the navcon. The navcon retains the view controllers in its current stack - you don't need to retain them yourself.

Generally the way to push a view controller is like such:

UIViewController* detailVC = [[[MyDetailVC alloc] init] autorelease];
[self.navigationController pushViewController:detailVC animated:YES];

The navigation controller will retain the detailVC until it gets popped off the stack, at which point it will get released, its retain count will go to 0, and it will get deallocated.


I solved my problem with HTTPRequest, its needed to set the coockie persistence to false with this line of code:

[request setUseCookiePersistence:FALSE];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜