NSArray and tableview - iphone

I'm making a navigation-based application, where i have a file called DataService.m and my RootViewController
.m
in my DataService.m I'm calling
-(NSArray*)loadData
{
AlarmItem *item1 = [[[AlarmItem alloc] initWithTitle:#"TEST2"] autorelease];
AlarmItem *item2 = [[[AlarmItem alloc] initWithTitle:#"TEST3"] autorelease];
AlarmItem *item3 = [[[AlarmItem alloc] initWithTitle:#"TEST4"] autorelease];
AlarmItem *item4 = [[[AlarmItem alloc] initWithTitle:#"TEST5"] autorelease];
AlarmItem *item5 = [[[AlarmItem alloc] initWithTitle:#"TEST6"] autorelease];
NSMutableArray *items = [NSMutableArray arrayWithObjects:item1, item2, item3, item4, item5, NULL];
return items;
}
and in my RootViewCoontroller.m i have
- (IBAction)RefreshAlarmList:(id)sender
{
XMLDataService *myXML = [[XMLDataService alloc] init];
[myXML loadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:#selector(RefreshAlarmList:)];
self.navigationItem.rightBarButtonItem = refreshButton;
[refreshButton release];
}
When I run my simulator the tableView is empty.. how can i display my items ?

Dont autorelease the function after it load to the tableview then autorelease it.Then how u are displaying the data to the tableview.give action as reload data in tableview.

You can try one thing.Here in the delegate method cellForRowAtIndexPath , in last u should return the cell.It may work.
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = #"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. AlarmItem *item = [_items objectAtIndex:indexPath.row]; cell.textLabel.text = item.tagName;return cell;}

[myXML loadData];
This is returning an array, which presumably you wish to use as your table's data source, but you are doing nothing with it. You need to assign this to an array, which is a retained ivar in your view controller class, _items or items judging by your other comments:
self.items = [myXML loadData];

Related

Fetching data in background, but table view not updating

I want to switch to next view immediately using push view controller, so using below method to fetch data from web services. But this is not updating UITableView.
// vewDidLoad
[NSThread detachNewThreadSelector:#selector(setImage) toTarget:self withObject:nil];
-(void)setImage
{
if([type isEqualToString:#"Organisation"])
{
self.mGetDataDict = [MyEventApi members:self.mUserIdDict];
self.mRecievedDataDict = [self.mGetDataDict valueForKey:#"members"];
}
if([type isEqualToString:#"Individual"]){
self.mGetDataDict = [MyEventApi friends:self.mUserIdDict];
self.mRecievedDataDict = [self.mGetDataDict valueForKey:#"friends"];
}
if([self.mGetDataDict valueForKey:#"friends"] == [NSNull null])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"alert" message:#"You have not added any friend yet." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
else
{
self.mFrndNameArr = [[NSMutableArray alloc]init];
self.mFrndImgArr = [[NSMutableArray alloc]init];
self.mFirstNameArr = [[NSMutableArray alloc]init];
self.mLastNameArr = [[NSMutableArray alloc]init];
self.mFrndIdArr = [[NSMutableArray alloc]init];
self.mFrndMSinceArr = [[NSMutableArray alloc]init];
self.mFrndDescArr = [[NSMutableArray alloc]init];
self.mFrndNameArr = [self.mRecievedDataDict valueForKey:#"username"];
self.mFrndImgArr = [self.mRecievedDataDict valueForKey:#"image"];
self.mFirstNameArr = [self.mRecievedDataDict valueForKey:#"firstName"];
self.mLastNameArr = [self.mRecievedDataDict valueForKey:#"lastName"];
self.mFrndIdArr = [self.mRecievedDataDict valueForKey:#"id"];
self.mFrndMSinceArr = [self.mRecievedDataDict valueForKey:#"memberSince"];
self.mFrndDescArr = [self.mRecievedDataDict valueForKey:#"description"];
[self.mFriendsTable reloadData];
}
}
Below is cellForRowAtIndexPath method.
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell;
cell = [self.mFriendsTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSString *imageUrlString = [NSString stringWithFormat:#"http://www.myevent.co/%#", [self.mFrndImgArr objectAtIndex:indexPath.row]];
[imageUrlString stringByReplacingOccurrencesOfString:#"/" withString:#""];
UILabel *lblEventName = [[UILabel alloc]initWithFrame:CGRectMake(92, 5, 200, 25)];
lblEventName.font = [UIFont fontWithName:#"Helvetica-Bold" size:14];
lblEventName.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:lblEventName];
if([copyArr count] >0)
{
lblEventName.text = [copyArr objectAtIndex:indexPath.row];
}
else{
lblEventName.text = [self.mFrndNameArr objectAtIndex:indexPath.row];
}
asyncImageView = [[AsyncImageView alloc]initWithFrame:CGRectMake(1, 3, 85, 54)];
[asyncImageView loadImageFromURL:[NSURL URLWithString:imageUrlString]];
[cell.contentView addSubview:asyncImageView];
cell.textLabel.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0];
cell.contentView.backgroundColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0];
return cell;
}
The text data is fetched but images are not fetched until table scrolled. But if i use this way it shows the images also but switches to next view after all dat is fetched.
// vewDidLoad
[self setImage];
Please guide for above, is the way iam using threads wrong or any other way or method needs to be used here.
Since you are updating data in seperate thread ,You have to execute the reload on the main thread itself
instead of this
[self.mFriendsTable reloadData];
use this
[self.mFriendsTable performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:YES];

UITableView use plist make a pervious and next button?

I use UITableView with plist to make a tableview, than how to make a pervious/next button within the DetailView (without back to tableview and press next item)?
The program:
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableDictionary *labelDict = [[[NSMutableDictionary alloc]initWithContentsOfFile:[[[NSBundle mainBundle]bundlePath]stringByAppendingPathComponent:#"myData.plist"]] retain];
cellImages = [[NSMutableArray alloc ] initWithArray:[labelDict objectForKey:#"image"]];
cellTitles = [[NSMutableArray alloc] initWithArray:[labelDict objectForKey:#"title"]];
cellSubTitles = [[NSMutableArray alloc] initWithArray:[labelDict objectForKey:#"subtitle"]];
NSLog(#"%#", [[[NSBundle mainBundle] bundlePath]stringByAppendingPathComponent:#"myData.plist"]);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
cell.textLabel.text = [cellTitles objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [cellSubTitles objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.detailViewController) {
self.detailViewController = [[[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil] autorelease];
}
[self.navigationController pushViewController:self.detailViewController animated:YES];
self.detailViewController.detailImage.image = [UIImage imageNamed:[cellImages objectAtIndex:indexPath.row]];
self.detailViewController.detailDescriptionLabel.text = [cellTitles objectAtIndex:indexPath.row];
self.detailViewController.subTitle.text = [cellSubTitles objectAtIndex:indexPath.row];
self.detailViewController.title = nil;
}
Pass data arrays and current index to the detail view controller. Add actions to the buttons that will be selecting current record to dislpay.

iphone slow navigation due to data load

I'm newbie to objective-c . My problem is slow navigation between controllers.
When I jump from one controller to another it's really slow, because it gets data from the service, parse it and then display it. All this takes around 4-5 secs.
Now I've put all this data fetching in loadView of my DetailController. Is there anyway that I show the controller first and then display the data. Because as of now, when I select a row on my root controller, it shows activity and stays on root controller and then it navigates to the DetailController.
So it loads the data first and then displays it. Is there anyway that I can reverse this process, show the controller first and then display it..
this is what I'm doing
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DataCollection *collection = [DataCollection sharedObject];
Product *tempProduct = [[collection popularProducts] objectAtIndex:row] ;
ProductDetailViewController *tempProductDetail = [[ProductDetailViewController alloc] init];
tempProductDetail.homeViewProduct = tempProduct;
[tempProductDetail release];
}
and then the Detail Controller
- (void)loadView {
[super loadView];
// here's all the data loading and parsing ... which takes time
}
//Here's the method for downloading the data, I'm using a REST service to get all the data.
- (void) getProductData:(NSString*)productId{
NSMutableString *specificURL = [[NSMutableString alloc] initWithString:#"GetProductPage?id="];
[specificURL appendFormat:#"%#",productId];
[specificURL appendFormat:#"&dataSources=&accountId=&companyId=&version=1&cultureCode=sv&currencyId=2&format=json"];
NSDictionary *serverCategories = [[NSDictionary alloc] initWithDictionary:[appRequestController proceesRequest:specificURL]];
NSArray *categories = [[[serverCategories objectForKey:#"DataSources"] objectAtIndex:0] objectForKey:#"Items"];
[serverCategories release];
if ([[productsArray objectAtIndex:j] objectForKey:#"Name"] != [NSNull null]) {
[product setProductName:[[productsArray objectAtIndex:j] objectForKey:#"Name"]];
}
else {
[product setProductName:#""];
}
if ([[productsArray objectAtIndex:j] objectForKey:#"ThumbnailImage"] != [NSNull null]) {
[product setProductImage:[[productsArray objectAtIndex:j] objectForKey:#"ThumbnailImage"]];
}
else {
[product setProductImage:#""];
}
if ([[productsArray objectAtIndex:j] objectForKey:#"Price"] != [NSNull null]) {
[product setProductPrice:[[productsArray objectAtIndex:j] objectForKey:#"Price"]];
}
else {
[product setProductPrice:#""];
}
[[collection popularProducts] addObject:product];
[product release];
}
I've copy pasted junks of the code so that you can get an idea how I'm getting the data. Below is the code for cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *MyIdentifier = #"mainMenuIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
[cell setSelectedBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"highlightstrip.png"]]];
}
UILabel *productNameLbl = [[UILabel alloc] initWithFrame:CGRectMake(90, 8, 200,10)];
[productNameLbl setText:[NSString stringWithString:[[[[DataCollection sharedObject] popularProducts]objectAtIndex:indexPath.row] productName]]];
[productNameLbl setFont:[UIFont boldSystemFontOfSize:12.0]];
[cell addSubview:productNameLbl];
[productNameLbl release];
UILabel *productSubLbl = [[UILabel alloc] initWithFrame:CGRectMake(90, 22, 190,40)];
[productSubLbl setText:[NSString stringWithString:[[[[DataCollection sharedObject] popularProducts]objectAtIndex:indexPath.row] productSubHeader]]];
[productSubLbl setTextColor:[UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102/255.0 alpha:1.0]];
productSubLbl.lineBreakMode = UILineBreakModeWordWrap;
productSubLbl.numberOfLines = 3;
[productSubLbl setFont:[UIFont fontWithName:#"Arial" size:10]];
[cell addSubview:productSubLbl];
[productSubLbl release];
NSMutableString *url = [[NSMutableString alloc] initWithString:#""];
NSString *baseImageURL = #"http://samplesite.com/";
NSString *imagePath = [NSString stringWithString:[[[[DataCollection sharedObject] popularProducts]objectAtIndex:indexPath.row] productImage]];
[url appendString:baseImageURL];
[url appendString:imagePath];
NSURL *imageURL = [NSURL URLWithString:url];
NSData *data = [NSData dataWithContentsOfURL:imageURL];
UIImage *img = [[UIImage alloc] initWithData:data cache:NO];
UIImageView *imageView = [[UIImageView alloc] initWithImage:img];
[imageView setFrame:CGRectMake(10, 10, 70, 70)];
[cell addSubview:imageView];
[imageView release];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
Pass the url or product id to the detail view. Inside the viewDidLoad of the ProductDetail, create a background thread to retrieve your data. When you background thread finish, it will notify your ProductDetail controller with the detail. At that time, you update your ProductDetailView.
To get your data on a background thread you can use
NSThread
NSOperation
Pass the row into your ProductDetailViewController, and do the fetch in it's viewDidLoad method. You might also want to show a spinner (UIActivityIndicator), and you definitely should read up on background threads.
To make view available to user and loading data after some time you can use NSTimer.
Just have a NSTimer method which will be called in viewDidLoad method as
[NSTimer scheduledTimerWithTimeInterval:<#(NSTimeInterval)ti#> target:<#(id)aTarget#> selector:<#(SEL)aSelector#> userInfo:<#(id)userInfo#> repeats:<#(BOOL)yesOrNo#>]
put some time interval which will be calling your loading method after that.
Hope this helps.

UITableView ObjectAtIndex

I'm developing an iPhone app that is a tabViewController with one of the tabs including a tableView. Objects in the table can be touched to go to a splash screen with information for that specific object.
Here's how I set up the array tableView:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//each table view cell has its own identifier.
static NSString *cellIdentifier = #"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [sitesArray objectAtIndex:row];
cell.imageView.image = [imagesArray objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
- (void)viewDidLoad {
NSArray *pageHolder = [[NSArray alloc] initWithObjects:#"CSLP", #"NSLS", #"LSPA", #"SIOP", #"Transfer", nil];
self.pages = pageHolder;
[pageHolder release];
NSArray *sites = [[NSArray alloc] initWithObjects:#"CSLP", #"NSLS", #"LSPA", #"SIOP", #"Transfer Vision Program ", nil];
self.sitesArray = sites;
UIImage *cslp = [UIImage imageNamed:#"CSLP LOGO.png"];
UIImage *nsls = [UIImage imageNamed:#"NSLS LOGO.png"];
UIImage *lspa = [UIImage imageNamed:#"LSPA LOGO.png"];
UIImage *siop = [UIImage imageNamed:#"SIOP LOGO.png"];
UIImage *transfer = [UIImage imageNamed:#"TRANSFER LOGO.png"];
NSArray *images = [[NSArray alloc] initWithObjects: cslp, nsls, lspa, siop, transfer, nil];
[sites release];
self.imagesArray = images;
UIButton* modalViewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[modalViewButton addTarget:self action:#selector(modalViewAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *modalBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:modalViewButton];
self.navigationItem.rightBarButtonItem = modalBarButtonItem;
[modalBarButtonItem release];
[self.table reloadData];
}
And here's my didSelectRowAtIndexPath method
-(void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
NSInteger row = [indexPath row];
NSMutableDictionary *rowData = [table objectAtIndex:indexPath.row];
UIViewController *targetViewController = [rowData objectForKey:kViewControllerKey];
if (!targetViewController)
{
// The view controller has not been created yet, create it and set it to our menuList array
NSString *viewControllerName = [[pages objectAtIndex:indexPath.row] stringByAppendingString:#"ViewController"];
targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
[rowData setValue:targetViewController forKey:kViewControllerKey];
[targetViewController release];
}
SSARC_App_2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.orgsNavigationController pushNavigationItem:targetViewController animated:YES];
[delegate release];
}
The application crashes at the first call to objectAtIndex in the didSelectRowAtIndexPath method. The console states:
010-11-22 12:50:17.113 SSARC App
2[43470:207] -[UITableView
objectAtIndex:]: unrecognized selector
sent to instance 0x601e800 2010-11-22
12:50:17.116 SSARC App 2[43470:207]
* Terminating app due to uncaught exception
'NSInvalidArgumentException', reason:
'-[UITableView objectAtIndex:]:
unrecognized selector sent to instance
0x601e800'
* Call stack at first throw:
Now, I have a warning that says "UITableView may be unresponsive to ObjectAtIndex". I'm assuming this is the main issue here, however I'm unsure how to solve it. Interestingly enough I've searched for this issue everywhere, and cannot find it anywhere, so I'm curious to know if anyone has run into this problem and how to solve it. Any advice would be great. Let me know if you need more information.
I've been doing some coding on my own and I've gotten it to compile without any errors or warnings, but it still crashes. Currently this is what I have:
NSMutableDictionary *rowData = [self.menuList objectAtIndex:indexPath.row];
UIViewController *targetViewController = [rowData objectForKey:kViewControllerKey];
if (!targetViewController)
{
// The view controller has not been created yet, create it and set it to our menuList array
NSString *viewControllerName = [[pages objectAtIndex:indexPath.row] stringByAppendingString:#"ViewController"];
targetViewController = [[NSClassFromString(viewControllerName) alloc] init];//WithNibName:viewControllerName bundle:nil];
NSLog(#"targetViewController: %#", targetViewController);
[rowData setValue:targetViewController forKey:kViewControllerKey];
[targetViewController release];
}
SSARC_App_2AppDelegate *delegate = (SSARC_App_2AppDelegate*)[[UIApplication sharedApplication] delegate];
[[delegate orgsNavigationController] pushViewController:targetViewController animated:YES];
[delegate release];
delegate = nil;
The issue that the debugger reports is that 'viewControllerName' is 'Out of Scope'. I don't really understand what that means because when I use NSLog, viewControllerName is initialized. Does that mean it cannot find the class I'm referring to? Please let me know.
Assuming table is your UITableView, the call to [table objectAtIndex:indexPath.row] is completely nonsensical. It looks to me like you should be calling [pages objectAtIndex:indexPath.row] instead.
objectAtIndex should be called either for NSMutableArray Or NSArray. You cann't call it from UITableview Or CFDictionary Or CFString. So if you gets any warning Solve the warning first and then proceed further.

UITableView reloadData problem in UITabBar

I have a tabBar application that has ResultsNavController as 1 of my tabBar's Nav Controller, the View Controller is ResultsViewController and my tableViewPtr is connected to the tableView in IB which is under Main window.xib ResultsNavController/ResultsViewController/View/tableView.
After going to another tab to write to PureFun.plist, clicking on results view doesn't reload the table instantly with the new PureFun.plist. PureFun.plist was successfully written after i checked.
- (void)viewWillAppear:(BOOL)animated {
[self.tableViewPtr reloadData];
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [resultsDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"ResultsCellIdentifier";
UILabel *scoreStrLabel;
UILabel *dateStrLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
dateStrLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10,5.0,200,43)] autorelease];
dateStrLabel.tag = DATESTR_TAG;
dateStrLabel.font = [UIFont systemFontOfSize:18.0];
dateStrLabel.textAlignment = UITextAlignmentLeft;
dateStrLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:dateStrLabel];
scoreStrLabel = [[[UILabel alloc] initWithFrame:CGRectMake(250,5.0,50,43)] autorelease];
scoreStrLabel.tag = SCORESTR_TAG;
scoreStrLabel.font = [UIFont systemFontOfSize:18.0];
scoreStrLabel.textAlignment = UITextAlignmentRight;
scoreStrLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:scoreStrLabel];
}
else {
scoreStrLabel = (UILabel *)[cell.contentView viewWithTag:SCORESTR_TAG];
dateStrLabel = (UILabel *)[cell.contentView viewWithTag:DATESTR_TAG];
}
NSDictionary *dict = [resultsDataArray objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:#"h':'mma, EEE d MMM"];
NSDate *dateTested = [dict objectForKey:#"Date"];
NSString *dateStr = [formatter stringFromDate:dateTested];
NSString *scoreStr = [dict objectForKey:#"Score"];
scoreStrLabel.text = scoreStr;
dateStrLabel.text = dateStr;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 49.1;
}
- (void)viewDidLoad {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:#"PureFun.plist"];
NSArray *array = [[NSArray alloc] initWithContentsOfFile:myPathDocs];
self.resultsDataArray = array;
[array release];
[super viewDidLoad];
}
To catch the changes of the current view controller in your UITabBarController, try using the following UITabBarControllerDelegate method:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
// ...
}
This way you can trigger the reload manually. Sometimes, complex combinations of view controllers might get complex and hard to debug, and not all the "viewWillAppear:" methods are called as one thinks they should be.
I know my problem. my array wasn't reloaded in the viewWillAppear, so i copied the Setup codes in viewDidLoad to viewWillAppear and that solved it.
On a side note, UItableView problem may result from the data setup within DataSource, and [reload Data] might not be the main culprit in the case.