Search Results

Search found 1119 results on 45 pages for 'tableview'.

Page 2/45 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why does the last row of my tableview not align to the bottom of the screen

    - by Liam
    I have a view which consists of a tableview and a navigation bar. For my tableview I have implemented a 'Load more' row which will load current + pagesize every time it is clicked The way the loading works is very simple, every time it is clicked I just request the amount of rows I want to display e.g. 5, 10, 15 and so on. This request populates an array and I call [self.tableView reloadData] The issue I am experiencing is that when I go to the tableview the first time, it correctly loads and displays the tableview. However, if I 'Load more' it returns the correct amount and displays the correct number of cells but the last cell will not fit properly at the bottom of the screen, about 1/2 of it (or roughly the size of the navigation bar of the cell) appears below the bottom of the screen. I thought it was sufficient to just tell the tableview to reload itself. Do I need to use [self.tableView insertRowsAtIndexPaths ...] to do this.

    Read the article

  • Build a Drill Down TableView with arrays

    - by skiria
    I'm trying to build a Drill down tableview to show the information that I have in a hierachy of arrays and classes. I have 3 classes: class Video { nameVideo, id, description, user... } class Topic {nameTopic, topicID, NSMutableArray videos; } class Category {nameCategory, categoryID, NSMUtableArray topics} And then in my app delegate I defined //AppDelegate.h NSMutableArray categories; The app display the tableView with nameCategory, but then, when I select a row it shows a tableview with 0 rows. If I check, for the second view the NumberOfRowsInSection, it returns me 0. I supose that the error is that I don't build correctly the provisional array called tableDataSource, I don't know the reason why it doesn't copy the new information on this array. ` - (void)viewDidLoad { [super viewDidLoad]; appDelegate = (TSCAppDelegate *)[[UIApplication sharedApplication] delegate]; //self.title = @"Categoria"; if(CurrentLevel == 0) { //Initialize our table data source NSArray *tempArray = [[NSArray alloc] init]; self.tableDataSource = tempArray; [tempArray release]; self.tableDataSource = appDelegate.categories; self.navigationItem.title = @"Categoria"; CurrentTitle = @"Categoria"; } else { self.navigationItem.title = CurrentTitle; } } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSLog (@"contador_ %i,", [self.tableDataSource count]); //--> On the second view it is 0! return [self.tableDataSource count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]autorelease]; } // Configure the cell. if (CurrentLevel == 0) { Category *aCategory = [self.tableDataSource objectAtIndex:indexPath.row]; cell.text = aCategory.nameCategory; } if (CurrentLevel == 1) { Topic *aTopic = [self.tableDataSource objectAtIndex:indexPath.row]; cell.text = aTopic.nameTopic; } else if ([CurrentLevel == 0]){ Topic *aTopic = [self.tableDataSource objectAtIndex:indexPath.row]; cell.text = aTopic.nameTopic; //NSLog(@"inside!!"); } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //Get the actual Category Category *aCategory = [self.tableDataSource objectAtIndex:indexPath.row]; //NSLog (@" CATEGORY: %@", aCategory.nameCategory); //NSLog (@" CATEGORY: %i", aCategory.categoryID); //NSLog (@" TOPICS OF CATEGORY: %i", [aCategory.topics count]); //Prepare to tableview. navegaTableViewController *nvController = [[navegaTableViewController alloc] initWithNibName:@"navegaTableView" bundle:[NSBundle mainBundle]]; //Increment the Current View nvController.CurrentLevel += 1; //Set the title; nvController.CurrentTitle = @"Topic"; nvController.tableDataSource = aCategory.topics; //Push the new table view on the stack [self.navigationController pushViewController:nvController animated:YES]; [nvController release]; } `

    Read the article

  • Multiple errors while adding searching to app

    - by Thijs
    Hi, I'm fairly new at iOS programming, but I managed to make a (in my opinion quite nice) app for the app store. The main function for my next update will be a search option for the app. I followed a tutorial I found on the internet and adapted it to fit my app. I got back quite some errors, most of which I managed to fix. But now I'm completely stuck and don't know what to do next. I know it's a lot to ask, but if anyone could take a look at the code underneath, it would be greatly appreciated. Thanks! // // RootViewController.m // GGZ info // // Created by Thijs Beckers on 29-12-10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "RootViewController.h" // Always import the next level view controller header(s) #import "CourseCodes.h" @implementation RootViewController @synthesize dataForCurrentLevel, tableViewData; #pragma mark - #pragma mark View lifecycle // OVERRIDE METHOD - (void)viewDidLoad { [super viewDidLoad]; // Go get the data for the app... // Create a custom string that points to the right location in the app bundle NSString *pathToPlist = [[NSBundle mainBundle] pathForResource:@"SCSCurriculum" ofType:@"plist"]; // Now, place the result into the dictionary property // Note that we must retain it to keep it around dataForCurrentLevel = [[NSDictionary dictionaryWithContentsOfFile:pathToPlist] retain]; // Place the top level keys (the program codes) in an array for the table view // Note that we must retain it to keep it around // NSDictionary has a really useful instance method - allKeys // The allKeys method returns an array with all of the keys found in (this level of) a dictionary tableViewData = [[[dataForCurrentLevel allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] retain]; //Initialize the copy array. copyListOfItems = [[NSMutableArray alloc] init]; // Set the nav bar title self.title = @"GGZ info"; //Add the search bar self.tableView.tableHeaderView = searchBar; searchBar.autocorrectionType = UITextAutocorrectionTypeNo; searching = NO; letUserSelectRow = YES; } /* - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } */ /* - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } */ /* - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } */ /* - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } */ //RootViewController.m - (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar { searching = YES; letUserSelectRow = NO; self.tableView.scrollEnabled = NO; //Add the done button. self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneSearching_Clicked:)] autorelease]; } - (NSIndexPath *)tableView :(UITableView *)theTableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(letUserSelectRow) return indexPath; else return nil; } //RootViewController.m - (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText { //Remove all objects first. [copyListOfItems removeAllObjects]; if([searchText length] &gt; 0) { searching = YES; letUserSelectRow = YES; self.tableView.scrollEnabled = YES; [self searchTableView]; } else { searching = NO; letUserSelectRow = NO; self.tableView.scrollEnabled = NO; } [self.tableView reloadData]; } //RootViewController.m - (void) searchBarSearchButtonClicked:(UISearchBar *)theSearchBar { [self searchTableView]; } - (void) searchTableView { NSString *searchText = searchBar.text; NSMutableArray *searchArray = [[NSMutableArray alloc] init]; for (NSDictionary *dictionary in listOfItems) { NSArray *array = [dictionary objectForKey:@"Countries"]; [searchArray addObjectsFromArray:array]; } for (NSString *sTemp in searchArray) { NSRange titleResultsRange = [sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch]; if (titleResultsRange.length &gt; 0) [copyListOfItems addObject:sTemp]; } [searchArray release]; searchArray = nil; } //RootViewController.m - (void) doneSearching_Clicked:(id)sender { searchBar.text = @""; [searchBar resignFirstResponder]; letUserSelectRow = YES; searching = NO; self.navigationItem.rightBarButtonItem = nil; self.tableView.scrollEnabled = YES; [self.tableView reloadData]; } //RootViewController.m - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (searching) return 1; else return [listOfItems count]; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (searching) return [copyListOfItems count]; else { //Number of rows it should expect should be based on the section NSDictionary *dictionary = [listOfItems objectAtIndex:section]; NSArray *array = [dictionary objectForKey:@"Countries"]; return [array count]; } } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if(searching) return @""; if(section == 0) return @"Countries to visit"; else return @"Countries visited"; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell... if(searching) cell.text = [copyListOfItems objectAtIndex:indexPath.row]; else { //First get the dictionary object NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; NSArray *array = [dictionary objectForKey:@"Countries"]; NSString *cellValue = [array objectAtIndex:indexPath.row]; cell.text = cellValue; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //Get the selected country NSString *selectedCountry = nil; if(searching) selectedCountry = [copyListOfItems objectAtIndex:indexPath.row]; else { NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; NSArray *array = [dictionary objectForKey:@"Countries"]; selectedCountry = [array objectAtIndex:indexPath.row]; } //Initialize the detail view controller and display it. DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; dvController.selectedCountry = selectedCountry; [self.navigationController pushViewController:dvController animated:YES]; [dvController release]; dvController = nil; } //RootViewController.m - (void) searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar { //Add the overlay view. if(ovController == nil) ovController = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:[NSBundle mainBundle]]; CGFloat yaxis = self.navigationController.navigationBar.frame.size.height; CGFloat width = self.view.frame.size.width; CGFloat height = self.view.frame.size.height; //Parameters x = origion on x-axis, y = origon on y-axis. CGRect frame = CGRectMake(0, yaxis, width, height); ovController.view.frame = frame; ovController.view.backgroundColor = [UIColor grayColor]; ovController.view.alpha = 0.5; ovController.rvController = self; [self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view]; searching = YES; letUserSelectRow = NO; self.tableView.scrollEnabled = NO; //Add the done button. self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneSearching_Clicked:)] autorelease]; } // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations. return YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Relinquish ownership any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. // For example: self.myOutlet = nil; } - (void)dealloc { [dataForCurrentLevel release]; [tableViewData release]; [super dealloc]; } #pragma mark - #pragma mark Table view methods // DATA SOURCE METHOD - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // DATA SOURCE METHOD - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // How many rows should be displayed? return [tableViewData count]; } // DELEGATE METHOD - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Cell reuse block static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell's contents - we want the program code, and a disclosure indicator cell.textLabel.text = [tableViewData objectAtIndex:indexPath.row]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } //RootViewController.m - (void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText { //Remove all objects first. [copyListOfItems removeAllObjects]; if([searchText length] &gt; 0) { [ovController.view removeFromSuperview]; searching = YES; letUserSelectRow = YES; self.tableView.scrollEnabled = YES; [self searchTableView]; } else { [self.tableView insertSubview:ovController.view aboveSubview:self.parentViewController.view]; searching = NO; letUserSelectRow = NO; self.tableView.scrollEnabled = NO; } [self.tableView reloadData]; } //RootViewController.m - (void) doneSearching_Clicked:(id)sender { searchBar.text = @""; [searchBar resignFirstResponder]; letUserSelectRow = YES; searching = NO; self.navigationItem.rightBarButtonItem = nil; self.tableView.scrollEnabled = YES; [ovController.view removeFromSuperview]; [ovController release]; ovController = nil; [self.tableView reloadData]; } // DELEGATE METHOD - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // In any navigation-based application, you follow the same pattern: // 1. Create an instance of the next-level view controller // 2. Configure that instance, with settings and data if necessary // 3. Push it on to the navigation stack // In this situation, the next level view controller is another table view // Therefore, we really don't need a nib file (do you see a CourseCodes.xib? no, there isn't one) // So, a UITableViewController offers an initializer that programmatically creates a view // 1. Create the next level view controller // ======================================== CourseCodes *nextVC = [[CourseCodes alloc] initWithStyle:UITableViewStylePlain]; // 2. Configure it... // ================== // It needs data from the dictionary - the "value" for the current "key" (that was tapped) NSDictionary *nextLevelDictionary = [dataForCurrentLevel objectForKey:[tableViewData objectAtIndex:indexPath.row]]; nextVC.dataForCurrentLevel = nextLevelDictionary; // Set the view title nextVC.title = [tableViewData objectAtIndex:indexPath.row]; // 3. Push it on to the navigation stack // ===================================== [self.navigationController pushViewController:nextVC animated:YES]; // Memory manage it [nextVC release]; } /* // Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source. [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } } */ /* // Override to support rearranging the table view. - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ @end

    Read the article

  • iOS: click counter for row in tableview

    - by roger.arliner21
    I am developing and tableView in which in each row I have to display the click counter and row number.Each cell must have an initial click counter value of 0 when application is initialized. Then increment the click counter value within a cell whenever a user clicks on the cell. I have take 26 fixed rows. I have taken tableData.plist file as in the attached image. I am initializing the self.dataArray with the plist . Now I want to do implementation in the didSelectRowAtIndexPath delegate method,if any row is tapped that row's click counter should increment. - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"tableData" ofType:@"plist"]; self.dataArray = [NSMutableArray arrayWithContentsOfFile:path];//array initialized with plist } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.dataArray count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *kCustomCellID = @"MyCellID"; UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(160.0f, 2.0f, 30.0f, 20.0f)]; UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(160.0f, 24.0f, 30.0f, 30.0f)]; label2.textColor = [UIColor grayColor]; UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:kCustomCellID]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCustomCellID] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } if([self.dataArray count]>indexPath.row) { label1.text = [[self.dataArray objectAtIndex:indexPath.row] objectForKey:@"Lable1"]; label2.text =[[self.dataArray objectAtIndex:indexPath.row] objectForKey:@"Lable2"]; } else { label1.text = @""; label2.text =@""; } [cell.contentView addSubview:label1]; [cell.contentView addSubview:label2]; [label1 release]; [label2 release]; return cell; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //implementation for row counter incrementer. }

    Read the article

  • Get a tableview insertRowsAtIndexPaths to accept indexOfObject?

    - by Emil
    Hey. I have a code snippet that looks like this: [tableView beginUpdates]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[array indexOfObject:[array objectAtIndex:indexPath.row]]] withRowAnimation:UITableViewRowAnimationLeft]; [tableView endUpdates]; [tableView reloadData]; It gets executed when a user clicks on an accessory. The first part is only there to provide a smooth animation, and does not really matter, as the tableView is reloaded milliseconds later, but as I said, it's there to provide an animation. It is supposed to move a selected object from its current indexPath to the value from an array at the same indexPath. Obviously, this code does not work, so I just want to know what can be done to fix it? PS: I get a warning when compiling, too. The usual "passing argument 1 of 'arrayWithObject:' makes pointer from integer without a cast..." (line 3)

    Read the article

  • NSOperation unable to load data on the TableView

    - by yeohchan
    I have a problem in NSOperation. I tried many ways but it would run behind the screen, but will not make it appear on the my table view. Can anyone help me out with this. I am new to NSOperation. Recents.h #import <UIKit/UIKit.h> #import "FlickrFetcher.h" @interface Recents : UITableViewController { FlickrFetcher *fetcher; NSString *name; NSData *picture; NSString *picName; NSMutableArray *names; NSMutableArray *pics; NSMutableArray *lists; NSArray *namelists; NSOperationQueue *operationQueue; } @property (nonatomic,retain)NSString *name; @property (nonatomic,retain)NSString *picName; @property (nonatomic,retain)NSData *picture; @property (nonatomic,retain)NSMutableArray *names; @property (nonatomic,retain)NSMutableArray *pics; @property(nonatomic,retain)NSMutableArray *lists; @property(nonatomic,retain)NSArray *namelists; @end Recents.m #import "Recents.h" #import "PersonList.h" #import "PhotoDetail.h" @implementation Recents @synthesize picName,picture,name,names,pics,lists,namelists; // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization self.title=@"Recents"; } return self; } - (void)beginLoadingFlickrData{ NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(synchronousLoadFlickrData) object:nil]; [operationQueue addOperation:operation]; [operation release]; } - (void)synchronousLoadFlickrData{ fetcher=[FlickrFetcher sharedInstance]; NSArray *recents=[fetcher recentGeoTaggedPhotos]; [self performSelectorOnMainThread:@selector(didFinishLoadingFlickrDataWithResults:) withObject:recents waitUntilDone:NO]; } - (void)didFinishLoadingFlickrDataWithResults:(NSArray *)recents{ for(NSDictionary *dic in recents){ [names addObject:[fetcher usernameForUserID:[dic objectForKey:@"owner"]]]; if([[dic objectForKey:@"title"]isEqualToString:@""]){ [pics addObject:@"Untitled"]; }else{ [pics addObject:[dic objectForKey:@"title"]]; } NSLog(@"OK!!"); } [self.tableView reloadData]; [self.tableView flashScrollIndicators]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; operationQueue = [[NSOperationQueue alloc] init]; [operationQueue setMaxConcurrentOperationCount:1]; [self beginLoadingFlickrData]; self.tableView.rowHeight = 95; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [super dealloc]; } #pragma mark - #pragma mark Table View Data Source Methods - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return[names count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIdentifier] autorelease]; } cell.detailTextLabel.text=[names objectAtIndex:indexPath.row]; cell.textLabel.text=[pics objectAtIndex:indexPath.row]; //UIImage *image=[UIImage imageWithData:[self.lists objectAtIndex:indexPath.row]]; //cell.imageView.image=image; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { fetcher=[[FlickrFetcher alloc]init]; PhotoDetail *scroll=[[PhotoDetail alloc]initWithNibName:@"PhotoDetail" bundle:nil]; scroll.titleName=[self.pics objectAtIndex:indexPath.row]; scroll.picture = [UIImage imageWithData:[self.lists objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:scroll animated:YES]; }

    Read the article

  • TableView doesnt show any Data(CoreData) - App crashe

    - by brush51
    Hey @all, i cant read my data from my database. I have an app with a tabbarcontroller. in the first tab the iphone camera takes a picture from a barcode and send the result to another view (CameraReturnDetailViewController). In CameraReturnDetailViewController is the savebutton, and here is the code from this save button: - (IBAction)saveAndQuitScan:(id) sender { XLog(@"saveAndQuitScan button wurde geklickt!"); ProjectQRCodeAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; NSManagedObjectContext *context = [appDelegate managedObjectContext]; NSManagedObject *newData; newData = [NSEntityDescription insertNewObjectForEntityForName:@"BarcodeDaten" inManagedObjectContext:context]; [newData setValue:dataLabel.text forKey:@"Barcode_CD"]; NSError *error; [context save:&error]; //Aktuelle ansicht (self) animiert verlassen [self dismissModalViewControllerAnimated:YES]; // Nachdem die ansicht verlassen wurde, // auf das zweite Tab wechseln(scanverlauf) /** TO DO - Funktioniert noch nicht **/ [self.tabBarController setSelectedIndex:1]; } Now, my aim is to show the taba in the second tab, in a TableView (ScansViewController): - (void)viewDidLoad { [super viewDidLoad]; if (managedObjectContext_ == nil) { managedObjectContext_ = [(ProjectQRCodeAppDelegate *)[[UIApplication sharedApplication]delegate] managedObjectContext]; NSLog(@"After managedObjectContext: %@", managedObjectContext_); } myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; myTableView.delegate = self; myTableView.dataSource = self; myTableView.autoresizesSubviews = YES; self.navigationItem.title = @"Code Liste"; self.view = myTableView; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [itemsList count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } return cell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSString *selectDay = [NSString stringWithFormat:@"%d", indexPath.row]; TableDetailViewController *fvController = [[TableDetailViewController alloc] initWithNibName:@"TableDetailViewController" bundle:[NSBundle mainBundle]]; fvController.selectDay = selectDay; [self.navigationController pushViewController:fvController animated:YES]; [fvController release]; fvController = nil; } - (void) configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath { NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath]; cell.textLabel.text = [[managedObject valueForKey:@"Barcode_CD"] description]; } - (NSFetchedResultsController *) fetchedResultsController { if (fetchedResultsController_ !=nil) { return fetchedResultsController_; } NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"BarcodeDaten" inManagedObjectContext:self.managedObjectContext]; [fetchRequest setEntity:entity]; [fetchRequest setFetchBatchSize:20]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Barcode_CD" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; aFetchedResultsController.delegate = self; self.fetchedResultsController = aFetchedResultsController; [aFetchedResultsController release]; [fetchRequest release]; [sortDescriptor release]; [sortDescriptors release]; NSError *error = nil; if (![fetchedResultsController_ performFetch:&error]) { XLog(@"Error: %@, %@", error, [error userInfo]); abort(); } return fetchedResultsController_; } At first i get this error when i choosed the second tab(ScansViewController): " Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'BarcodeDaten'' " The Name is correct but i dont understand my mistake. No data is showed in the Tableview, why? Have I missed something..? Or something wrong? Thanks for help, brush51

    Read the article

  • Tableview not drilling down

    - by JoshD
    I have a Tableview which is loaded with a dummy list of exercises. I need to drill to a different page. My didSelectRow is being called, but not implementing the method. The app is a tab bar navigation app that loads a UITableView. #import <UIKit/UIKit.h> @interface Schedule : UIViewController <UITableViewDelegate, UITableViewDataSource> { NSArray *mySchedule; } @end #import "Schedule.h" #import "AnotherViewController.h" @implementation Schedule - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return mySchedule.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //create a cell UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; //fill it with contents cell.textLabel.text = [mySchedule objectAtIndex:indexPath.row]; //return it return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil]; [self.navigationController pushViewController:anotherViewController animated:YES]; [anotherViewController release]; } /* // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { NSString *myFile = [[NSBundle mainBundle] pathForResource:@"exercise" ofType:@"plist"]; mySchedule = [[NSArray alloc] initWithContentsOfFile:myFile]; [super viewDidLoad]; }

    Read the article

  • get current selected button cell placed inside tableview using cocoa

    - by Swati
    hi i have a NSTableView i have two columns A and B B contains some data A contains custom button the button is added to column A using this: Below code is placed inside awakeFromNib method NSButtonCell *buttonCell = [[[NSButtonCell alloc] init] autorelease]; [buttonCell setBordered:NO]; [buttonCell setImagePosition:NSImageOnly]; [buttonCell setButtonType:NSMomentaryChangeButton]; [buttonCell setImage:[NSImage imageNamed:@"uncheck.png"]]; [buttonCell setSelectable:TRUE]; [buttonCell setTag:100]; [buttonCell setTarget:self]; [buttonCell setAction:@selector(selectButtonsForDeletion:)]; [[myTable tableColumnWithIdentifier:@"EditIdentifier"] setDataCell:buttonCell]; Some code in display cell of nstableview: -(void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex { if(tableView == myTable) { if([[tableColumn identifier] isEqualToString:@"DataIdentifier"]) { } else if([[tableColumn identifier] isEqualToString:@"EditIdentifier"]) { NSButtonCell *zCell = (NSButtonCell *)cell; [zCell setTag:rowIndex]; [zCell setTitle:@"abc"]; [zCell setTarget:self]; [zCell setAction:@selector(selectButtonsForDeletion:)]; } } } now i want that when i click on the button the image of button cell gets changed as well as i want to do some coding. When button gets clicked then by default the tableView's reference gets passed. How can i get the button cell reference i looked here for similar problem: Cocoa: how to nest a button inside a Table View cell? but i am unable to add button inside column of NSTableView. How i change the image: - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; { if(tableView == myTable) { if([[tableColumn identifier] isEqualToString:@"EditIdentifier"]) { NSButtonCell *aCell = (NSButtonCell *)[[tableView tableColumnWithIdentifier:@"EditIdentifier"] dataCellForRow:row]; NSInteger index = [[aCell title]intValue]; if([self.selectedIndexesArray count]>0) { if(![self.selectedIndexesArray containsObject:[NSNumber numberWithInt:index]]) { [aCell setImage:[NSImage imageNamed:@"check.png"]]; [self.selectedIndexesArray addObject:[NSNumber numberWithInt:index]]; } else { [aCell setImage:[NSImage imageNamed:@"uncheck.png"]]; [self.selectedIndexesArray removeObjectAtIndex:[selectedIndexesArray indexOfObject:[NSNumber numberWithInt:index]]]; } } else { [aCell setImage:[NSImage imageNamed:@"check.png"]]; [self.selectedIndexesArray addObject:[NSNumber numberWithInt:index]]; } } } } I have debugged the code and found that proper tag and titles are passed but image applies on more than one button cell, this is too very irregular. cant understand how its working!!! Any suggestions what am i doing wrong??

    Read the article

  • Cant change text in custom cell

    - by darkman
    I created a custom cell to display a text a two images, when the user select the cell, the image is suposed to change, i can acess the properties of the cell, but cant change then : - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; CustomCell *cell = (CustomCell *)[self.tableView cellForRowAtIndexPath:indexPath]; cell.check.image = setImage:[UIImage imageNamed:@"1355327732_checkbox-checked"]; [cell.check setImage:[UIImage imageNamed:@"1355327732_checkbox-checked"]]; } cell.check is a UIImageView Am i missing something?

    Read the article

  • Adding Insert Row in tableView

    - by user333624
    Hello everyone, I have a tableView that loads its data directly from a Core Data table with a NSFetchedResultsController. I'm not using an intermediate NSMutableArray to store the objects from the fetch results; I basically implemented inside my UITableViewController the protocol method numberOfRowsInSection and it returns the numberOfObjects inside a NSFetchedResultsSectionInfo. id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section]; and then I configure the cell content by implementing configureCell:atIndexPath and retrieving object info from the fetchedResultController but right now I have a generic configuration for any object (to avoid complications) cell.textLabel.text = @"categoria"; I also have a NavigationBar with a custom edit button at the right that loads my own selector called customSetEditing. What I'm trying to accomplish is to load an "Insert Cell" at the beginning of the tableView so when I tap it, it creates a new record. This last part is easy to implement the problem is that I dont's seem to be able to load the insert row or any row when I tap on the navigation bar edit button. this is the code for my customSetEditing: - (void) customSetEditing { [super setEditing:YES animated:YES]; [self.tableView setEditing:YES animated:YES]; [[self tableView] beginUpdates]; //[[self tableView] beginUpdates]; UIBarButtonItem *customDoneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(customDone)]; [self.navigationItem.rightBarButtonItem release]; self.navigationItem.rightBarButtonItem = customDoneButtonItem; //[categoriasArray insertObject:[NSNull null] atIndex:0]; NSMutableArray *indexPaths = [[NSMutableArray alloc] initWithObjects:[NSIndexPath indexPathForRow:0 inSection:0],nil ]; [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop]; //[indexPaths release]; [self.tableView reloadData];} Before adding the:[self.tableView reloadData]; I was getting an out of bounds error plus a program crash and although the program is not crashing it is not loading anything. I have seen many examples of similar situations in stackoverflow (by the way is an excellent forum with very helpful and nice people) none of the examples seems to work for me. Any ideas?

    Read the article

  • Get CoreLocation Update before TableView population?

    - by Clemens
    hi, i have the corelocation stuff in an uitableview controller. i actually want to get a distance from two locations and print that distance in a tableview cell. the problem is, that the tableview is filled before all the corelocation stuff happens. how can i make corelocation makes all updates before the table is filled? heres my class: // // EntriesListViewController.m // OEAW_App // // Created by Clemens on 6/6/10. // Copyright 2010 MyCompanyName. All rights reserved. // import "EntriesListViewController.h" import "EntryDetailController.h" @implementation EntriesListViewController @synthesize locationManager; @synthesize delegate; NSMutableDictionary *entries; NSMutableDictionary *dictionary; CLLocation *coords; /- (id) init { self = [super init]; if (self != nil) { self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; } return self; }/ (CLLocationManager *)locationManager { if (locationManager != nil) { return locationManager; } locationManager = [[CLLocationManager alloc] init]; locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; locationManager.delegate = self; return locationManager; } (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //coords.longitude = newLocation.coordinate.longitude; //coords.latitude = newLocation.coordinate.latitude; coords = newLocation; NSLog(@"Location: %@", [newLocation description]); } (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { NSLog(@"Error: %@", [error description]); } (void)viewDidLoad { //[[MyCLController alloc] init]; //[locationManager startUpdatingLocation]; [[self locationManager] startUpdatingLocation]; //---initialize the array--- //entries = [[NSMutableArray alloc] init]; //---add items--- //NSString *Path = [[NSBundle mainBundle] bundlePath]; //NSString *DataPath = [Path stringByAppendingPathComponent:@"Memorials.plist"]; dictionary = [[NSDictionary alloc] initWithContentsOfURL:[NSURL URLWithString: @"http://akm.madison.at/memorials.xml"]]; /*NSDictionary *dssItem = [dictionary objectForKey:@"1"]; NSString *text = [dssItem objectForKey:@"text"]; */ //entries = [[NSMutableDictionary alloc] init]; NSLog(@"%@", dictionary); //Path get the path to MyTestList.plist NSString *path=[[NSBundle mainBundle] pathForResource:@"Memorials" ofType:@"plist"]; //Next create the dictionary from the contents of the file. NSDictionary *dict=[NSDictionary dictionaryWithContentsOfFile:path]; //now we can use the items in the file. // self.name.text = [dict valueForKey:@"Name"] ; NSLog(@"%@",[dict valueForKey:@"Name"]); //---set the title--- self.navigationItem.title = @"Türkendenkmäler"; [super viewDidLoad]; } (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 [dictionary count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell... NSArray *keys = [dictionary allKeys]; id key = [keys objectAtIndex:indexPath.row]; NSDictionary *tmp = [dictionary objectForKey:key]; NSString *name = [tmp objectForKey:@"name"]; cell.textLabel.text = name; cell.font = [UIFont fontWithName:@"Helvetica" size:12.0]; CLLocation *location = [[CLLocation alloc] initWithLatitude:[[tmp valueForKey:@"coords_x"] floatValue] longitude:[[tmp valueForKey:@"coords_y"] floatValue]]; /*CLLocation *newLoc = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude];*/ //locationController = [[MyCLController alloc] init]; int distance = [coords distanceFromLocation:location]; NSLog(@"%@",distance); cell.detailTextLabel.text = [NSString stringWithFormat:@"%@m",distance]; //NSLog(@"%@", [getLocation newLoc]); return cell; } (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { EntryDetailController *detailViewController = [[EntryDetailController alloc] initWithNibName:@"EntryDetailController" bundle:nil]; //detailViewController.entrySelected = [dictionary objectAtIndex:indexPath.row]; NSArray *keys = [dictionary allKeys]; id key = [keys objectAtIndex:indexPath.row]; NSDictionary *tmp = [dictionary objectForKey:key]; NSString *name = [tmp objectForKey:@"name"]; detailViewController.entrySelected_name = name; NSString *location = [tmp objectForKey:@"location"]; detailViewController.entrySelected_location = location; NSString *type = [tmp objectForKey:@"type"]; detailViewController.entrySelected_type = type; NSString *slug = [tmp objectForKey:@"slug"]; detailViewController.entrySelected_slug = slug; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; } (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } (void)dealloc { [entries release]; [super dealloc]; } @end

    Read the article

  • how to make a tableview to be grouped style without indenting cells

    - by Ying
    Hi, I want a tableview without floating headers and footers, but in the UITableViewStylePlain style. When I used a grouped style tableview, it draws this rounded rectangle around my cells, and it is annoying!! Is there a setting to turn this off? I have tried tableView.backgroundView = nil; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.autoresizingMask = UIViewAutoresizingNone; All don't work. Does anyone have any idea how to do this? Thanks

    Read the article

  • iPhone tableview: titleForHeaderInSection derived from array

    - by Nic Hubbard
    I have a tableview that is populated by an array. Currently the tableview has no grouping. What I would like to do is check a value of each array object, such as State, and group all the CA items together, all the OR items together, etc. Then, assign those groups a title. The array is dynamic, and will grow and get new values in the future, so I can't hardcode titles, I would like these to somehow come from my initial array. Currently I am using the following, but it does not take into account sorting of the array, or if I removed all of the items in the array that have to do with California. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (section == 0) { return @"California"; } else if (section == 1) { return @"Washington"; } else { return @"Utah"; } }//end tableView So, I am confusing myself as to how this would be possible. Any tips would be appreciated.

    Read the article

  • tableView resize problem when pushing another view while keyboard is showing

    - by Rollin_s
    I have a tableview controller under a navigation controller. Some of my table cells contain text fields, so when I tap on them, a keyboard will show up and automatically resize (shrink) the bounds of my tableview. The bounds is then restored when the keyboard is dismissed programmatically by calling resignFirstResponder on my text field. Some of my cells would push a new view controller into the view stack when tapped on, so I first resign my current textfield before pushing the view controller: - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (currentEditingTextField != nil) { [currentEditingTextField resignFirstResponder]; currentEditingTextField = nil; } return indexPath; } The problem is when I navigate back to my table view, the bounds of the tableview is sized as if the keyboard is still there. I know this because the scroll indicator only reaches right above where the keyboard was and there is empty view space below the table view. Anybody experienced this and know of a solution? Thanks

    Read the article

  • numberOfSectionsInTableView is requested in/after viewDidLoad ONLY if tableview is empty

    - by Ben Packard
    A simple tableviewController, empty. A modal that can be launched from a button. No data in the data source for the tableview, and no rows displayed. I open the modal, use it to add an item, and return to the tableview controller. The tableview updates itself automatically, and the new row is displayed. I add a second item. The table view does NOT update automatically. I can tell by logging inside numberOfSectionsInTableView that even if I go to add the first item and cancel, the tableview refreshes - it asks for the number of sections, rows, and the cell to display (if there is one). But not if there is one pre-existing row in the table. I've scoured my code but can't find anything that would cause the tableview to know when the first item is added, but none afterwards. Any ideas? EDIT - I have further narrowed my issue so will close this shortly and post a more specific question

    Read the article

  • How to remove seprator in tableView?

    - by AJPatel
    i make one tableview in which i add button type cell using custom cell.....looks good but when their is less cell in tableview at that time seprator looks very bad...... in design so thier is any solution than tell me............ i try to remove seprator from design but it not work.... Thanks in advance.......... - (void)viewDidLoad { self.navigationItem.title = @"My List"; self.tblView.separatorStyle = UITableViewCellSeparatorStyleNone; [[self tableView] setRowHeight:70]; [[self tableView] setBackgroundColor:[UIColor blackColor]]; Helath_ndroidAppDelegate *appDeleg = (Helath_ndroidAppDelegate *)[[UIApplication sharedApplication] delegate]; NSMutableArray *temp1 =[[NSMutableArray alloc] init]; appDeleg.recipCategoryFromDatabase = temp1; [temp1 release]; dataBase *objData = [[[dataBase alloc] init] autorelease]; [objData selectrecepFromDatabase]; [[self tableView] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLineEtched]; [super viewDidLoad]; }

    Read the article

  • iPhone SDK Tableview Datasource singleton error

    - by mrburns05
    I basically followed apple "TheElements" sample and changed "PeriodicElements" .h & .m to my own "SortedItems" .h & .m During compile I get this error: "Undefined symbols: "_OBJC_CLASS_$_SortedItems", referenced from: __objc_classrefs__DATA@0 in SortedByNameTableDataSource.o ld: symbol(s) not found collect2: ld returned 1 exit status " here is my SortedItems.m file #import "SortedItems.h" #import "item.h" #import "MyAppDelegate.h" @interface SortedItems(mymethods) // these are private methods that outside classes need not use - (void)presortItemsByPhysicalState; - (void)presortItemInitialLetterIndexes; - (void)presortItemNamesForInitialLetter:(NSString *)aKey; - (void)presortItemsWithPhysicalState:(NSString *)state; - (NSArray *)presortItemsByNumber; - (NSArray *)presortItemsBySymbol; - (void)setupItemsArray; @end @implementation SortedItems @synthesize statesDictionary; @synthesize itemsDictionary; @synthesize nameIndexesDictionary; @synthesize itemNameIndexArray; @synthesize itemsSortedByNumber; @synthesize itemsSortedBySymbol; @synthesize itemPhysicalStatesArray; static SortedItems *sharedSortedItemsInstance = nil; + (SortedItems*)sharedSortedItems { @synchronized(self) { if (sharedSortedItemsInstance == nil) { [[self alloc] init]; // assignment not done here } } return sharedSortedItemsInstance; // note: Xcode (3.2) static analyzer will report this singleton as a false positive // '(Potential leak of an object allocated') } + (id)allocWithZone:(NSZone *)zone { @synchronized(self) { if (sharedSortedItemsInstance == nil) { sharedSortedItemsInstance = [super allocWithZone:zone]; return sharedSortedItemsInstance; // assignment and return on first allocation } } return nil; //on subsequent allocation attempts return nil } - (id)copyWithZone:(NSZone *)zone { return self; } - (id)retain { return self; } - (unsigned)retainCount { return UINT_MAX; //denotes an object that cannot be released } - (void)release { //do nothing } - (id)autorelease { return self; } // setup the data collection - init { if (self = [super init]) { [self setupItemsArray]; } return self; } - (void)setupItemsArray { NSDictionary *eachItem; // create dictionaries that contain the arrays of Item data indexed by // name self.itemsDictionary = [NSMutableDictionary dictionary]; // physical state self.statesDictionary = [NSMutableDictionary dictionary]; // unique first characters (for the Name index table) self.nameIndexesDictionary = [NSMutableDictionary dictionary]; // create empty array entries in the states Dictionary or each physical state [statesDictionary setObject:[NSMutableArray array] forKey:@"Solid"]; [statesDictionary setObject:[NSMutableArray array] forKey:@"Liquid"]; [statesDictionary setObject:[NSMutableArray array] forKey:@"Gas"]; [statesDictionary setObject:[NSMutableArray array] forKey:@"Artificial"]; MyAppDelegate *ad = (MyAppDelegate *)[[UIApplication sharedApplication]delegate]; NSMutableArray *rawItemsArray = [[NSMutableArray alloc] init]; [rawItemsArray addObjectsFromArray:ad.items]; // iterate over the values in the raw Items dictionary for (eachItem in rawItemsArray) { // create an atomic Item instance for each Item *anItem = [[Item alloc] initWithDictionary:eachItem]; // store that item in the Items dictionary with the name as the key [itemsDictionary setObject:anItem forKey:anItem.title]; // add that Item to the appropriate array in the physical state dictionary [[statesDictionary objectForKey:anItem.acct] addObject:anItem]; // get the Item's initial letter NSString *firstLetter = [anItem.title substringToIndex:1]; NSMutableArray *existingArray; // if an array already exists in the name index dictionary // simply add the Item to it, otherwise create an array // and add it to the name index dictionary with the letter as the key if (existingArray = [nameIndexesDictionary valueForKey:firstLetter]) { [existingArray addObject:anItem]; } else { NSMutableArray *tempArray = [NSMutableArray array]; [nameIndexesDictionary setObject:tempArray forKey:firstLetter]; [tempArray addObject:anItem]; } // release the Item, it is held by the various collections [anItem release]; } // release the raw Item data [rawItemsArray release]; // create the dictionary containing the possible Item states // and presort the states data self.itemPhysicalStatesArray = [NSArray arrayWithObjects:@"something",@"somethingElse",@"whatever",@"stuff",nil]; [self presortItemsByPhysicalState]; // presort the dictionaries now // this could be done the first time they are requested instead [self presortItemInitialLetterIndexes]; self.itemsSortedByNumber = [self presortItemsByNumber]; self.itemsSortedBySymbol = [self presortItemsBySymbol]; } // return the array of Items for the requested physical state - (NSArray *)itemsWithPhysicalState:(NSString*)aState { return [statesDictionary objectForKey:aState]; } // presort each of the arrays for the physical states - (void)presortItemsByPhysicalState { for (NSString *stateKey in itemPhysicalStatesArray) { [self presortItemsWithPhysicalState:stateKey]; } } - (void)presortItemsWithPhysicalState:(NSString *)state { NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] ; NSArray *descriptors = [NSArray arrayWithObject:nameDescriptor]; [[statesDictionary objectForKey:state] sortUsingDescriptors:descriptors]; [nameDescriptor release]; } // return an array of Items for an initial letter (ie A, B, C, ...) - (NSArray *)itemsWithInitialLetter:(NSString*)aKey { return [nameIndexesDictionary objectForKey:aKey]; } // presort the name index arrays so the items are in the correct order - (void)presortItemsInitialLetterIndexes { self.itemNameIndexArray = [[nameIndexesDictionary allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; for (NSString *eachNameIndex in itemNameIndexArray) { [self presortItemNamesForInitialLetter:eachNameIndex]; } } - (void)presortItemNamesForInitialLetter:(NSString *)aKey { NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] ; NSArray *descriptors = [NSArray arrayWithObject:nameDescriptor]; [[nameIndexesDictionary objectForKey:aKey] sortUsingDescriptors:descriptors]; [nameDescriptor release]; } // presort the ItemsSortedByNumber array - (NSArray *)presortItemsByNumber { NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"acct" ascending:YES selector:@selector(compare:)] ; NSArray *descriptors = [NSArray arrayWithObject:nameDescriptor]; NSArray *sortedItems = [[itemsDictionary allValues] sortedArrayUsingDescriptors:descriptors]; [nameDescriptor release]; return sortedItems; } // presort the itemsSortedBySymbol array - (NSArray *)presortItemsBySymbol { NSSortDescriptor *symbolDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES selector:@selector(localizedCaseInsensitiveCompare:)] ; NSArray *descriptors = [NSArray arrayWithObject:symbolDescriptor]; NSArray *sortedItems = [[itemsDictionary allValues] sortedArrayUsingDescriptors:descriptors]; [symbolDescriptor release]; return sortedItems; } @end I followed the sample exactly - don't know where I went wrong. Here is my "SortedByNameTableDataSource.m" #import "SortedByNameTableDataSource.h" #import "SortedItems.h" #import "Item.h" #import "ItemCell.h" #import "GradientView.h" #import "UIColor-Expanded.h" #import "MyAppDelegate.h" @implementation SortedByNameTableDataSource - (NSString *)title { return @"Title"; } - (UITableViewStyle)tableViewStyle { return UITableViewStylePlain; }; // return the atomic element at the index - (Item *)itemForIndexPath:(NSIndexPath *)indexPath { return [[[SortedItems sharedSortedItems] itemsWithInitialLetter:[[[SortedItems sharedSortedItems] itemNameIndexArray] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; } // UITableViewDataSource methods - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"ItemCell"; ItemCell *itemCell = (ItemCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (itemCell == nil) { itemCell = [[[ItemCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; itemCell = CGRectMake(0.0, 0.0, 320.0, ROW_HEIGHT); itemCell.backgroundView = [[[GradientView alloc] init] autorelease]; } itemCell.todo = [self itemForIndexPath:indexPath]; return itemCell; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // this table has multiple sections. One for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] // return the count of that array return [[[SortedItems sharedSortedItems] itemNameIndexArray] count]; } - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { // returns the array of section titles. There is one entry for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] return [[SortedItems sharedSortedItems] itemNameIndexArray]; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { return index; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // the section represents the initial letter of the element // return that letter NSString *initialLetter = [[[SortedItems sharedSortedItems] itemNameIndexArray] objectAtIndex:section]; // get the array of elements that begin with that letter NSArray *itemsWithInitialLetter = [[SortedItems sharedSortedItems] itemsWithInitialLetter:initialLetter]; // return the count return [itemsWithInitialLetter count]; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { // this table has multiple sections. One for each unique character that an element begins with // [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z] // return the letter that represents the requested section // this is actually a delegate method, but we forward the request to the datasource in the view controller return [[[SortedItems sharedSortedItems] itemNameIndexArray] objectAtIndex:section]; } @end

    Read the article

  • Populate tableView with more than one array

    - by Ewoods
    The short version: Is there a way to populate one specific row in a tableView with one value from one array, then populate another row in that same tableView with one value from a different array? For example, cell 1 would have the first value from Array A, cell 2 would have the first value from Array B, cell 3 would have the first value from Array C, etc. The long version: I hope this isn't too confusing. I've got an array of names, and then three more arrays with actions associated with those people. For example, the names array has Jim, Bob, and Sue, and then there's an array for eating, reading, and sleeping that records every time each person does one of these things (all of these arrays are populated from a MySQL database). The names array is used to populate a root tableView. Tapping on one of the names brings up a detail view controller that has another tableView that only has three rows. This part is all working fine. What I want to happen is when I tap on a name, it moves to the detail view and the three cells would then show the last event for that person for each of the three activities. Tapping on one of those three events then moves to a new view controller with a tableView that shows every event for that category. For example, if I tapped on Bob, the second page would show the last time Bob ate, read, and slept. Tapping on the first row would bring up a table that showed every time Bob has eaten. So far I've only been able to populate the second tableView with all of the rows from one of the arrays. I need it the other way around (one row from all of the arrays).

    Read the article

  • How to set background color of tableView

    - by Praveen
    Hi Folks, I have tried all the way but could not succeed to set backgroundColor of TableView. setting tableView.backgroundColor and/or cell.backgroundColor to clearColor didn't work when the parent view controller was UIViewContoller. My nib file structure is FileOwner View UITableView (Note: i set the TableView to groupedTable section) First attempt, I created the UIView in the code viewDidLoad UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, 300)] autorelease; [view setBackgroundColor:UIColor blueColor]; // color it just to see if it is created at the right place [self.tableView sendSubViewToBack:view]; It works but it hides the content of cell. I am able to see the content of header but not cell content. (But when i change the co-ordinate of view(0,150,160,300) then i am able to see the cell's content but then it loose the backgroundColor of tableview. Second attempt, I created the imageView View ImageView UITableView and set the self.tableView.backgroundColor = [UIColor clearColor]; but did not work. I googled but did not the peaceful answer.

    Read the article

  • Access problem with NSMutableArray

    - by pbcoder
    Hi, my problem is that I can't access my NSMutableArray in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}. I create my NSMutableArray here: nodes = [xmlDoc nodesForXPath:@"/xml/items/item/short_desc" error:nil]; if (nodes != nil && [nodes count] >= 1) { for (int i = 0; i < [nodes count]; i++) { CXMLElement *resultElement = [nodes objectAtIndex:i]; result = [[[[resultElement attributeForName:@"data"] stringValue] copy] autorelease]; [short_desc addObject:result]; } } and I can print out the content of short_desc everywhere with: NSLog([short_desc objectAtIndex:0]); but not in: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ..... NSString *date = [name objectAtIndex:0]; labelDate.text = date; ..... return cell;} if I use: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ..... NSString *date = @"text..."; labelDate.text = date; ..... return cell;} it works correctly. ANY SOLUTION FOR THIS PROBLEM???

    Read the article

  • Clicking the TableView leads you to the another View

    - by lakesh
    I am a newbie to iPhone development. I have already created an UITableView. I have wired everything up and included the delegate and datasource. However, instead of adding a detail view accessory by using UITableViewCellAccessoryDetailClosureButton, I would like to click the UITableViewCell and it should lead to another view with more details about the UITableViewCell. My view controller looks like this: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{ NSArray *tableItems; NSArray *images; } @property (nonatomic,retain) NSArray *tableItems; @property (nonatomic,retain) NSArray *images; @end ViewController.m #import "ViewController.h" #import <QuartzCore/QuartzCore.h> @interface ViewController () @end @implementation ViewController @synthesize tableItems,images; - (void)viewDidLoad { [super viewDidLoad]; tableItems = [[NSArray alloc] initWithObjects:@"Item1",@"Item2",@"Item3",nil]; images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"clock.png"],[UIImage imageNamed:@"eye.png"],[UIImage imageNamed:@"target.png"],nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return tableItems.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //Step 1:Check whether if we can reuse a cell UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; //If there are no new cells to reuse,create a new one if(cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"]; UIView *v = [[UIView alloc] init]; v.backgroundColor = [UIColor redColor]; cell.selectedBackgroundView = v; //changing the radius of the corners //cell.layer.cornerRadius = 10; } //Set the image in the row cell.imageView.image = [images objectAtIndex:indexPath.row]; //Step 3: Set the cell text content cell.textLabel.text = [tableItems objectAtIndex:indexPath.row]; //Step 4: Return the row return cell; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ cell.backgroundColor = [ UIColor greenColor]; } @end Need some guidance on this.. Thanks.. Please pardon me if this is a stupid question.

    Read the article

  • iPhone Tableview Use Cells in Horizontal Scrolling not Vertical

    - by norskben
    Hi Guys This is not an uiview orientation question, I want to Have the iphone in Portrait or Landscape, and I want a standard tableview(controller?) that will display cells in a vertical strip down the iphone and the tableview scrolls horizontally. -I.e. a 100% normal tableview, that is rotated 90deg without rotating the phone orientation Is this possible?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >