views:

24

answers:

1

I use original method XML data can show in rootviewcontroller TableView. When i use New Procedure it show the table only no data. How can i show the data in New Method?

Original Method

  1. appDelegate.m (setup XML & load the data)
  2. rootviewController.m (use nsarray & load the data into table view)

New Method

  1. appDelegate.m (setup XML & load the data)
  2. mainviewController.m (Setup up UIVEW & button key), (when button press, go to rootviewcontroller.m)
  3. rootviewController.m (use nsarray & load the data into table view)

appDeleagte.m

- (void)addbookToList:(NSArray *)books {
[self.rootViewController insertBooks:books];

mainviewcontroller.h

#import <UIKit/UIKit.h>
@class RootViewController;
@interface MainViewController : UIViewController {

IBOutlet RootViewController *rvController; 
}

- (IBAction) startButton;
@end

mainviewcontroller.m

-(IBAction)startPage {
 rvController = [[RootViewController alloc] initWithNibName:@"RootView" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:rvController animated:YES];

rootviewcontroller.m

- (void)viewDidLoad {
[super viewDidLoad];

self.bookList = [NSMutableArray array];

self.tableView.rowHeight = 60.0;

 [self addObserver:self forKeyPath:@"bookList" options:0 context:NULL];
}
A: 

If you call addBookToList: in your app delegate at a time that the root view controller doesn't yet exist, nothing will happen (sending message to nil). Store the books array, and pass it to your root view controller after you've created it, but before you push it onto the stack in your navigation controller.

Johan Kool
Thanks for information, coz i'm beginning. Which array command should i use to stock the books array. thx.
Do read the documentation on memory management, or consult a Cocoa book for beginners. You "store" an array by keeping a reference to it. By calling `[myArray retain]` you ensure it sticks around until you let go of it by calling `[myArray release]`. Make sure you understand this principle, as it is a key part of coding for iPhone, so do read up on it.
Johan Kool