Why I am unable to push viewcontroller to the next viewcontroller?
I am working on sockets in objective-c so i wrote a function for getting response of server when my condition comes true i want to push to the next view controller but it is not pushing or presenting plz help some code is given here
this is my function
void receiveData(CFSocketRef s,
CFSocketCallBackType type,
CFDataRef address,
const void *data,
void *info)
{
LoginViewController *lvc = [[LoginViewController alloc] init];
char *buffer = (char *)CFDataGetBytePtr((CFDataRef)data);
if (strstr(buffer, "LCNF|ACPT") == NULL)
{
NSLog(@"%@",data);
[lvc alert];
}
else
[lvc goToWatchList];
}
my "goToWatchlist" method is:
-(void)goToWatchList
{
WatchListViewController *wlController = [[WatchListViewController allo开发者_StackOverflow中文版c] initWithNibName:@"WatchListViewController" bundle:nil];
[self presentModalViewController:wlController animated:YES];
[wlController release];
}
Thanx in advance
I have done something very similar before. Are you sure it even reaches your [lvc goToWatchList];
within receiveData
? Also check that your reading from socket is not blocking the thread!
Also check your xib file - if this cannot be found it won't appear either... (Ups - already been mentioned while I was typing...)
Make sure this is happening on the main thread. Also make sure that wlController is not nil after the init message in case the nib cannot be found or there is a problem with it.
You create a new LoginViewController here:
LoginViewController *lvc = [[LoginViewController alloc] init];
But I don't see where you are adding that to a view. You push your WatchListViewController onto that, but it can't appear because its parent (the LoginViewController) is not showing up. Yes, the loadview on LoginViewController -(void)loadView will be called because you are adding something to it (the WatchViewController), but since that view isn't being displayed, it doesn't need to load the LoginViewController's view.
Try adding this code to the end of receiveData:
[[[UIApplication sharedApplication] keyWindow] addSubview:lvc.view];
If that doesn't work, try changing to the goToWatchListFunction to present the modal view controller on the [[UIApplication sharedApplication] keyWindow].
精彩评论