2013-12-24 3 views
0

Пожалуйста, дайте предложение этого кодавыборка tabledata в КСНЕ от ONEView контроллера anoher контроллер представления

appdelegate.h

#import <UIKit/UIKit.h> 
    #import "MainViewController.h" 

    @interface MainAppDelegate : UIResponder <UIApplicationDelegate> 
    { 
     UINavigationController *navigationController; 
    } 

    @property (strong, nonatomic) UIWindow *window; 
    @property (nonatomic, retain) UINavigationController *navigationController; 
    @property (nonatomic, retain) MainViewController *MainviewController; 

    appdelegate.m 



    #import "MainAppDelegate.h" 
    #import "MainViewController.h" 
    @implementation MainAppDelegate 
    @synthesize navigationController, MainviewController; 
    @synthesize matri; 

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     [email protected]""; 
     // Override point for customization after application launch. 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

     self.MainviewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; 
     self.navigationController = [[UINavigationController alloc] init]; 
     self.window.rootViewController = self.navigationController; 
     [self.navigationController pushViewController:self.MainviewController animated:YES]; 
     [self.navigationController setNavigationBarHidden:YES animated:NO]; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } //plaese provide detail of code 

mainviewcontroller.h

#import <UIKit/UIKit.h> 
    #import "SecViewController.h" 

    @interface MainViewController : UIViewController <UITableViewDelegate,UITableViewDataSource> 

    mainviewcontroller.m 

    #import "MainViewController.h" 
    #import "MainAppDelegate.h" 

    @interface MainViewController() 


    @end 

    @implementation MainViewController 


    { 
     NSArray *tableData; 
     MainAppDelegate *appDelegate; 
    } 
    //@synthesize pun; 


    - (void)viewDidLoad 
    { 
     [super viewDidLoad]; 

     //appDelegate=(MainAppDelegate*)[[UIApplication sharedApplication]delegate ]; 

     tableData = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4", nil]; 
     NSLog(@"tabledata : %@", tableData); 
     // Do any additional setup after loading the view, typically from a nib. 
    } 

    -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     NSLog(@"tabledata : %@", tableData); 
     return [tableData count]; 
    } 


    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    { 
     static NSString *simpleTableIdentifier = @"SimpleTableItem"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

     if (cell == nil) 
     { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
     } 



     cell.textLabel.text = [tableData objectAtIndex:indexPath.row]; 
     // NSLog(@"Value at index:%@",cell.textLabel.text); 

     return cell; 

    } 


    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

     SecViewController *SecView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; 
     SecView.newarray =[tableData objectAtIndex:indexPath.row]; 

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


    } 


    - (void)didReceiveMemoryWarning 
    { 
     [super didReceiveMemoryWarning]; 
     // Dispose of any resources that can be recreated. 
    } 


    @end 
  1. Я не понимаю, как позвонить econdview с первого взгляда помочь мне
  2. код дырки файл предназначен для создания простого вида таблицы и вызвать secviewcontroller
  3. может кто-нибудь помочь мне предоставить код, как позвонить secview объекту и как использовать контроллер MainView

и я также создал nsmutablearray с объектом newarray и синтезировал его. может ли кто-нибудь понять этот код и дать краткое описание этого кода и предложить мне то, что я пропустил, потому что я могу проверить это и вызвать secviewcontroller от mainviewcontroller.

ответ

0

использовать этот код в приложение файл delegate.m

YourviewController *loginVc = [[YourviewController alloc]  initWithNibName:@"YourviewController" bundle:nil]; 
      self.navigationController = [[UINavigationController alloc] initWithRootViewController:loginVc]; 
    self.window.rootViewController = self.navigationController; 

     self.navigationController.navigationBarHidden =YES; 
     [self.window makeKeyAndVisible]; 
+0

что yourviewcontrolle это первый вид контроллер класс – MeghaJain

+0

кий добавить это, но я не показываю ошибку, loginvc не идентифицируется – MeghaJain

+0

нет я просто добавить, что у написать мое имя вида – MeghaJain

0

Проверьте это:

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
     [email protected]""; 
     // Override point for customization after application launch. 
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

     self.MainviewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; 
     self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.MainviewController]; //Embedding your navigationController in mainviewcontroller 
     self.window.rootViewController = self.navigationController; 

     [self.navigationController setNavigationBarHidden:YES animated:NO]; 
     [self.window makeKeyAndVisible]; 
     return YES; 
    } 

И тогда в вашем mainViewCOntroller.m

#import"appdelegate.h" 

, а затем в

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

     SecViewController *SecView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; 
     SecView.newarray =[tableData objectAtIndex:indexPath.row]; 
     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
     [delegate.navigationController pushViewController:SecView animated:YES ]; 


    } 
+0

AppDelegate * appDelegate = (AppDelegate *) [[UIApplication sharedApplication] необходимо сделать – MeghaJain

+0

@ Amit205 есть разница .. потому что, делая это, будет обычный контейнер viewCntrollers, доступный где угодно .. –

+0

@ Amit205 какая проблема вы в этом коде. –

0

Сделайте это.

self.MainviewController = [[MainviewController alloc]  initWithNibName:@"MainviewController" bundle:nil]; 
      self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.MainviewController]; 
    self.window.rootViewController = self.navigationController; 

     self.navigationController.navigationBarHidden =YES; 
     [self.window makeKeyAndVisible]; 
+0

ya я пишу точный и пишу – MeghaJain

+0

, пожалуйста, не отправляйте несколько ответов. если вам нужны новые изменения, тогда отредактируйте свой ответ ... – Jitendra

+0

моя проблема все еще не решена. Могу ли я отправить мне точный код для табличного представления в xib не в раскадровке по адресу [email protected] – MeghaJain

Смежные вопросы