I'm working on an application in which I have a UITableView, two arrays and one UISegmentedControl. Now I need to when the UISegmentedControl value is 0 loaded in the UITableView data from the array one, and when UISegmentedControl has value 1 loaded data from array two. Simply, I need to switch the data to be loaded into UITableView from arrays. I tried to use a bool, but it does not work, I also think that it's not ideal.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
allTableData = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"BWM" andDescription:#"Auto" andDefinice:#"Osobni"],nil ];
allTableData2 = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"Renault" andDescription:#"Dodavka" andDefinice:#"Velka"],nil ];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
long rowCount;
if(self.isSwich == false)
rowCount = allTableData.count;
else
rowCount = allTableData2.count;
return rowCount;
}
- (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];
Food* food;
if(self.isSwitch == false)
{
food = [allTableData objectAtIndex:indexPath.row];
}
else
{
food = [allTableData2 objectAtIndex:indexPath.row];
}
cell.textLabel.text = food.name;
cell.detailTextLabel.text = food.description;
return cell;
}
-(IBAction)switchdata:(id)sender
{
if(self.myswitcher.selectedSegmentIndex == 0)
{
isSwitch = FALSE;
}
else
{
isSwitch = TRUE;
}
}
You are missing a call to reloadData in the witchdata: implementation. Adding this call will fix the problem.
I also think that it's not ideal.
That's right. Rather than storing a flag that says which array to use for your data source, store the array itself. This would eliminate all the ifs on the isSwitch property:
// Declare this as an instance variable, and use it
// in your data source methods.
NSArray *theSource;
- (void)viewDidLoad {
[super viewDidLoad];
allTableData = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"BWM" andDescription:#"Auto" andDefinice:#"Osobni"],nil ];
allTableData2 = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"Renault" andDescription:#"Dodavka" andDefinice:#"Velka"], nil];
theSource = allTableData;
}
-(IBAction)switchdata:(id)sender {
if(self.myswitcher.selectedSegmentIndex == 0) {
theSource = allTableData;
} else {
theSource = allTableData2;
}
[myTable reloadData];
}
Alternatively you could make isSwitch an integer, and use it as an index into an array that has your allTableData at index zero and allTableData2 at index one:
NSArray *sources;
int sourceIndex;
// Use sources[sourceIndex] as the current source
- (void)viewDidLoad {
[super viewDidLoad];
allTableData = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"BWM" andDescription:#"Auto" andDefinice:#"Osobni"], nil];
allTableData2 = [[NSMutableArray alloc] initWithObjects:
[[Food alloc] initWithName:#"Renault" andDescription:#"Dodavka" andDefinice:#"Velka"],nil ];
sources = #[allTableData, allTableData2];
sourceIndex = 0;
}
-(IBAction)switchdata:(id)sender {
sourceIndex = self.myswitcher.selectedSegmentIndex;
[myTable reloadData];
}
Firstly, in your switchData: method - use self.switch to access its setters,getters.
Secondly, Rather than using a bool value to track segment value, use the direct segment value.
Replace your self.switch value with self.switcher.selectedSegmentIndex in the table view delegate,datasource methods.
Finally, reload table view in your switchData: method.
Related
Hi I have used NsurlSession for integrating web services when I get response from services I am using NSObject for mapping key and values pairs.
After the process is done in NSObject class I want to display that data in my TableList.
For this I wrote the code below, but after mapping all objects in my NSObject class.
How can I display them in tableList?
Please help me.
mainclass:-
#import "ViewController.h"
#interface ViewController (){
BacGroundGetMethodServiceClass * get;
ModelObject1 * model1;
NSString * alertmessage;
UITableView * MaintableView;
}
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
get = [[BacGroundGetMethodServiceClass alloc]init];
get.delegate = self;
[get getServieCalling:#"my url"];
model1 = [[ModelObject1 alloc]init];
}
//got response here from services using protocols
- (void) GetCallService1: (id)MainResponse{
dispatch_async(dispatch_get_main_queue(), ^{
if ([MainResponse isKindOfClass:[NSDictionary class]] && MainResponse[#"error"]){
alertmessage = [MainResponse objectForKey:#"message"];
[self ShowingAlertMesaage:alertmessage];
}else if ([MainResponse count] == 0){
[self ShowingAlertMesaage:#"Server not responding please try again"];
}
else{
[model1 loadingservices :MainResponse];
}
});
}
//Crating TableList :-
-(void)createTableList{
//Create UITableList:-
[MaintableView removeFromSuperview];
MaintableView = [[UITableView alloc] initWithFrame:CGRectMake(5, 118, self.view.frame.size.width-10, self.view.frame.size.height-75) style:UITableViewStylePlain];
MaintableView.delegate = self;
MaintableView.dataSource = self;
MaintableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
MaintableView.separatorStyle = UITableViewCellSeparatorStyleNone;
MaintableView.contentInset = UIEdgeInsetsMake(0, 0, 75, 0);
MaintableView.bounces = NO;
[self.view addSubview:MaintableView];
}
//TableList Delegate Methods:-
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"HistoryCell";
// Similar to UITableViewCell, but
UITableViewCell *cell = (UITableViewCell *)[MaintableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
return cell;
}
#end
model Object class:-
#import "ModelObject1.h"
#implementation ModelObject1
#synthesize MasterId,Name;
-(void)loadingservices :(id)mainDictionary{
for (NSDictionary *obj in mainDictionary) {
if([obj objectForKey:#"Name"] && [obj objectForKey:#"id"]) {
Name = [obj objectForKey:#"Name"];
MasterId = [obj objectForKey:#"id"];
}
}
}
#end
If you want a list then you need array in proper JSON object.
i.e
(
{
Name = value1,
MasterId = value2
},
{
Name = value1,
MasterId = value2
},
{
Name = value1,
MasterId = value2
}
)
You need to create multiple objects of ModelObject1, i.e if in your JSON array you have 3 objects then you need to create 3 object of your ModelObject1.
You can achieve this by creating new Method or Class.
for example here is some code.
for(int i = 0; i < array.count; i++)
{
ModelObject1 *model1 = [[ModelObject1 alloc]init];
[model1 loadingservices :array[i];
//store model1 in to any array and use that array to display list in array.
}
You can display the data as below.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return yourModelClassArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"HistoryCell";
// Similar to UITableViewCell, but
UITableViewCell *cell = (UITableViewCell *)[MaintableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
ModelObject1 *model1 = yourModelClassArray[indexPath.row];
cell.textLabel.text = model1.Name;
return cell;
}
Hi i am beginner in ios in my project i have implemented horizontal TableList
ok everything is fine and i could able to create horizontal TableList loading static data
but i want load data now from array list for this i have tried below code but it showing exception [__NSArrayI objectAtIndex:]: index 5 beyond bounds [0 .. 4]' and when i add objects as like paidList array there is no errors coming but when i use for loop for inserting objects it's showing exceptions
please help me what did i do here wrong?
my code:-
#import "ViewController.h"
#interface ViewController ()
{
NSArray * images;
NSArray * titles;
}
#end
#implementation ViewController
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
images = [[NSArray alloc]initWithObjects:#"5_64x64.png",#"6_64x64.png",#"7_64x64.png",#"8_64x64.png",#"9_64x64.png",nil];
titles = [[NSArray alloc]initWithObjects:#"Weather",#"Weather",#"E-Trade",#"Voice Recorder",#"News Reader", nil];
freeList =[[NSMutableArray alloc]init];
for (int i = 0; images.count; ++i) {
ListItem *item = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:[images objectAtIndex:i]] text:[titles objectAtIndex:i]];
[freeList addObject:item];
}
NSLog(#"free list is %#",freeList);
ListItem *item6 = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:#"10_64x64.png"] text:#"Game Pack"];
ListItem *item7 = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:#"11_64x64.png"] text:#"Movies"];
ListItem *item8 = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:#"12_64x64.png"] text:#"Forecast"];
ListItem *item9 = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:#"10_64x64.png"] text:#"Game Pack"];
ListItem *item10 = [[ListItem alloc] initWithFrame:CGRectZero image:[UIImage imageNamed:#"10_64x64.png"] text:#"Game Pack"];
paidList = [[NSMutableArray alloc] initWithObjects: item6, item7, item8, item9, item10, nil];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (int)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 155.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSString *title = #"";
POHorizontalList *list;
if ([indexPath row] == 0) {
title = #"Top Free";
list = [[POHorizontalList alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 155.0) title:title items:freeList];
}
else if ([indexPath row] == 1) {
title = #"Top Paid";
list = [[POHorizontalList alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 155.0) title:title items:paidList];
}
[list setDelegate:self];
[cell.contentView addSubview:list];
return cell;
}
Your for loop condition is wrong.
for (int i = 0; images.count; ++i)
it should be
for (int i = 0; i < images.count; i++)
Good afternoon,
I used the following tutorial to create a TableView Navigation: http://www.techotopia.com/index.php/Implementing_TableView_Navigation_using_Xcode_Storyboards but with that example I can show static information.
Now I need to display images and texts from my database and I need some help to do that.
At the moment, that's my CarTableViewController.m
#import "CarTableViewController.h"
#import "CarTableViewCell.h"
#import "CarTableViewController.h"
#import "CarDetailViewController.h"
#implementation CarTableViewController
#synthesize carMakes = _carMakes;
#synthesize carModels = _carModels;
#synthesize carImages = _carImages;
- (void)viewDidLoad
{
[super viewDidLoad];
self.carMakes = [[NSArray alloc]
initWithObjects:#"Chevy",
#"BMW",
#"Toyota",
#"Volvo",
#"Smart", nil];
self.carModels = [[NSArray alloc]
initWithObjects:#"Volt",
#"Mini",
#"Venza",
#"S60",
#"Fortwo", nil];
self.carImages = [[NSArray alloc]
initWithObjects:#"chevy_volt.jpg",
#"mini_clubman.jpg",
#"toyota_venza.jpg",
#"volvo_s60.jpg",
#"smart_fortwo.jpg", nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.carModels count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"carTableCell";
CarTableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.makeLabel.text = [self.carMakes
objectAtIndex: [indexPath row]];
cell.modelLabel.text = [self.carModels
objectAtIndex:[indexPath row]];
UIImage *carPhoto = [UIImage imageNamed:
[self.carImages objectAtIndex: [indexPath row]]];
cell.carImage.image = carPhoto;
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"ShowCarDetails"])
{
CarDetailViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView
indexPathForSelectedRow];
detailViewController.carDetailModel = [[NSArray alloc]
initWithObjects: [self.carMakes
objectAtIndex:[myIndexPath row]],
[self.carModels objectAtIndex:[myIndexPath row]],
[self.carImages objectAtIndex:[myIndexPath row]],
nil];
}
}
#end
I need to put the information from my database (author, date and picture) to carMakes, carModels and carImages to display it. I can get the values from my PHP file with JSON, but I need some help with the NSArray with JSON result because I never used it.
How can I do that?
That's my JSON result:
[{"id":"15","user":"1","image":"http:\/\/farmaventas.es\/images\/farmaventaslogo.png","date":"2014-09-13"}]
Thanks in advance.
NSMutableArray* dataSource = [[NSMutableArray alloc] init];
NSMutableDictionary* chevyVolt = [[NSMutableDictionary alloc] init];
chevyVolt[#"Make"] = #"Chevy";
chevyVolt[#"Model"] = #"Volt";
chevyVolt[#"Image"] = #"chevy_volt.jpg";
dataSource[0] = chevyVolt;
NSMutableDictionary* clubman = [[NSMutableDictionary alloc] init];
-- etc --
Inside cellForRow--
NSMutableDictionary* cellData = dataSource[[indexPath row]];
cell.makeLabel.text = cellData[#"Make"];
cell.modelLabel.text = cellData[#"Model"];
-- etc --
When you receive your JSON data, you have to decide what row it pertains to. If you somehow know that id 15 is for a Chevy Volt, you then presumably copy info out of the corresponding JSON element into the dictionary for the Chevy Volt. (Or, if you wait to receive the JSON to add the Chevy Volt row (seems more likely), you construct the dictionary for the Volt as above and add it to the end of the dataSource array, with the added info from the JSON.)
For whatever reason I can't find this anywhere, but I am coding an iphone app and am trying to
filter a users contact list of people of known phone numbers using the ABAddressBook framework.
I want the contacts list, which is a UITableViewController, to be split up into 2 sections: contacts already on the app, and contacts not on the app. I have the contacts list stored in an NSArray and I need to figure out how to determine whether or not the contact in the array is in the app already or not.
Once this is done, I need to be able to add contacts from the already using the app section to a 'friends list' UITableViewController.
Thank you so much!
Here's my .m file code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.contacts = [[NSArray alloc]init];
[self getAllContacts];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//GETS RID OF WEIRD OVERLAP BUG ON TABLE VIEW CONTROLLER
[self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.contacts.count;
}
-(void)getAllContacts
{
APAddressBook *addressBook = [[APAddressBook alloc]init];
addressBook.fieldsMask = APContactFieldAll;
addressBook.filterBlock = ^BOOL(APContact *contact){
return (contact.phones.count > 0) && !(contact.firstName == nil && contact.lastName == nil);
};
[addressBook loadContacts:^(NSArray *apContacts, NSError *error) {
if(!error){
NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
for (APContact *AP in apContacts) {
Contact *contact = [Contact new];
contact.firstName = AP.firstName?[AP.firstName stringByAppendingString:#" "]:#"";
contact.lastName = AP.lastName?AP.lastName:#" ";
contact.fullName = [contact.firstName stringByAppendingString:contact.lastName];
if(AP.emails && [AP.emails count] > 0) {
contact.email = [AP.emails firstObject]?:nil;
}
if(AP.thumbnail ) {
contact.image = AP.thumbnail;
} else {
/* contact.image = [UIImage imageNamed:]; ADD GENERIC DEFAULT IMAGE*/
}
if(AP.phones && [AP.phones count] > 0) {
NSString *phone = [AP.phones firstObject];
contact.phoneNumber = [NSString formatNumber:phone];
contact.numberToDisplay = phone;
contact.identifier = [NSString formatNumber:phone];
} /*else {
contact.identifier = [AP.emails firstObject];
}*/
[dic setValue:contact forKey:contact.fullName];
}
self.contacts = [dic allValues];
[self setupContacts];
} else {
//write an alert error.description
}
}];
}
-(void)setupContacts{
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc]initWithKey:#"fullName" ascending:YES selector:#selector(caseInsensitiveCompare:)];
NSArray *descriptors = [NSArray arrayWithObject:descriptor];
self.contacts = [self.contacts sortedArrayUsingDescriptors:descriptors];
if (!self.selectedContacts) {
self.selectedContacts = [[NSMutableDictionary alloc]initWithCapacity:self.contacts.count];
}
self.tableView.allowsSelection = YES;
self.tableView.allowsMultipleSelection = YES;
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"ContactsCell";
ContactsCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = (ContactsCell *)[[ContactsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSInteger row = indexPath.row;
Contact *contact = [self.contacts objectAtIndex:row];
cell.mainTextLabel.text = contact.fullName;
cell.hidden = NO;
return cell;
}
I'm getting an error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.
because I'm adding an object to one instance of an array, but then reloading the table view from another instance of what is supposed to be the same array. How can I create a single instance of the array and just pass it around from class to class? I can do it easily in java, but in Objective-C you can't make static variables so I'm not sure how to do this.
EDIT: more code.
Here is a method from another class that is called in order to save a file. I'm using Core Data, so first it adds the file to the context (model), then to the array, then it saves the context. This method is in a class called 'Player'
-(BOOL)saveRecording {
Bank *B = [MusikerViewController daBank];
AudioTableViewController *ATVC2 = [MusikerViewController ATVControl];
NSLog(#"Place A");
AudioFile *myAudioFileMusicX314 = [[B addAudioFileEntityToModelWithDate:myDate andURLString:strPath] retain];
NSLog(#"Place B");
myAudioFileMusicX314.type = true;
[ATVC2 addAudioEntityToArray:myAudioFileMusicX314];
NSLog(#"Place C ***********************************************");
if(![B saveContext]) { //save context after adding file to keep consistancy
NSLog(#"addAudioFileEntityToModel is returning a nil managedObjectContext");
return NO;
}
NSLog(#"Place D");
[myDate release];
[strPath release];
[myAudioFileMusicX314 release];
[ATVC2 release];
NSLog(#"Place E");
return YES;
}
The following method is in the class that contains the table view--its caled AudioTableViewController
-(void)addAudioEntityToArray:(AudioFile *)event {
NSIndexPath *indexPath;
if(event.type) {
[[MusikerViewController recordingsArray] addObject:event];//self?
indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
}
else {
[[MusikerViewController downloadsArray] addObject:event];
indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
}
[[self tableView] setEditing:YES animated:NO];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
The following method adds the object to my model
- (AudioFile *)addAudioFileEntityToModelWithDate:(NSDate *)theD andURLString:(NSString *)str {
NSLog(#"addAudio...WithDate -- called");
sound = (AudioFile *)[NSEntityDescription insertNewObjectForEntityForName:#"AudioFile" inManagedObjectContext:managedObjectContext];
sound.creationDate = theD;
sound.soundPath = str; //set the sound path to the sound file's url
[self alertForTitle];
NSLog(#"No problems yet at place D - addaudio...String, sound title is %#", sound.title);
NSLog(#"Context at addAudioFileEntityToModel is: %#", managedObjectContext);
return sound;
}
here is the important parts of MusikViewController.h -- it keeps track of recordingsArray and downloadsArray
#interface MusikerViewController : UIViewController {
}
NSMutableArray *recordingsArray;
NSMutableArray *downloadsArray;
+ (NSMutableArray *)recordingsArray;
+ (NSMutableArray *)downloadsArray;
and MusikViewController.m
+ (NSMutableArray *)recordingsArray {
NSLog(#"recordingsArray called");
if(!recordingsArray) {
recordingsArray = [[NSMutableArray alloc] init];
NSMutableArray *bigTempArray = [[[[Bank alloc] init] autorelease] getFetchArray]; //change this
for(AudioFile *af in bigTempArray)
if(af.type) {
[recordingsArray addObject:af];
}
NSLog(#"recordingsArray exists");
}
return recordingsArray;
}
+ (NSMutableArray *)downloadsArray {
NSLog(#"recordingsArray called");
if(!downloadsArray) {
downloadsArray = [[NSMutableArray alloc] init];
// if(!bigTempArray)
NSMutableArray *bigTempArray = [[[[Bank alloc] init] autorelease] getFetchArray];
for(AudioFile *af in bigTempArray)
if(!af.type) {
[downloadsArray addObject:af];
}
}
return downloadsArray;
}
and some AudioTableViewController methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(#"Place F");
if(section == 0) {
return [[MusikerViewController recordingsArray] count];
}
else if (section == 1) {
return [[MusikerViewController downloadsArray] count];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
AudioFile *event;
if(indexPath.section == 0) {
event = (AudioFile *)[[MusikerViewController recordingsArray] objectAtIndex:indexPath.row];
} else if (indexPath.section == 1) {
NSLog(#"downAry indexPath caled at cellForRow...Path");
event = (AudioFile *)[[MusikerViewController downloadsArray] objectAtIndex:indexPath.row];
}
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
if(event.title) {
cell.detailTextLabel.text = [Player dateString:event.creationDate];
cell.textLabel.text = event.title;
} else {
cell.textLabel.text = [Player dateString:event.creationDate];
cell.detailTextLabel.text = nil;
}
return cell;
}
- (void)viewDidLoad //viewDidLoad for AudioTableViewController
{
[[self tableView] reloadData];
NSLog(#"viewDidLoad called for AudioTableViewController");
[super viewDidLoad];
self.title = #"Audio Files";//put this in application delegate
// Set up the buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
}
If your data model changes you need to either reload the tableView, or insert/remove the rows otherwise the tableview will freak out on you. It doesn't matter how many times tableView:numberOfRowsInSection is called, your data model can't return a different number without first reloading or updating the tableview.
Based on your logging my guess is that your downloads array is changing quantities. It makes it past the NSLog then dies in _endCellAnimationsWithContext.