从connectiondidfinish委托NSURLConnection调用viewcontroller另一个类

时间:2012-01-17 11:26:47

标签: iphone objective-c

尝试在NSUrlConection的connectiondidfinish委托方法中启动viewcontroller

// Sprequest.m继承自nsobject

- (void)connectionDidFinishLoading:(NSURLConnection *)conn {     
  NSLog(@"connectionDidFinishLoading ");  

  if(nStatus == 401)
  { 
     NSLog(@"called maincontroller to launch dvrview");   

     MainController *mainview =[[MainController alloc] init];
     [mainview reponseFromServer];

  }    
}  
//maincontroller.m from viewcontroller
-(void)reponseFromServer
{
  NSLog(@"response from server - main controller ");

  dvrView *dvrObj = [[dvrView alloc]initWithNibName:@"dvrView" bundle:nil];
  [self.navigationController pushViewController:dvrObj animated:YES];
}

这个dvr视图没有加载

1 个答案:

答案 0 :(得分:2)

Sprequest.m is inherited from NSObject , its not a viewController subclass so you cant use 

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

在Sprequest.m内部 您可以像这样

从appdelegate获取navigationController对象
((AppDelegate *)[UIApplication sharedApplication].delegate).navigationController

然后使用

[((AppDelegate *)[UIApplication sharedApplication].delegate).navigationController pushViewController:dvrObj animated:YES];