Search Results

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

Page 11/45 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • UICollectionView with one static cell and N dynamic ones from a fetchresultscontroller exception

    - by nflacco
    I'm trying to make a UITableView that shows a blog post and comments for that post. My setup is a tableview in storyboard with two dynamic prototype cells. The first cell is for the post and should never change. The second cell represents the 0 to N comments. My cellForRowAtIndexPath method shows the post cell properly, but fails to get the comment at the given index path (though if I comment out the fetch I get the appropriate number of comment cells with a green background that I set as a visual debug thing). let comment = fetchedResultController.objectAtIndexPath(indexPath) as Comment I get the following exception on this line: 2014-08-24 15:06:40.712 MessagePosting[21767:3266409] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]' *** First throw call stack: ( 0 CoreFoundation 0x0000000101aa43e5 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001037f9967 objc_exception_throw + 45 2 CoreFoundation 0x000000010198f4c3 -[__NSArrayM objectAtIndex:] + 227 3 CoreData 0x00000001016e4792 -[NSFetchedResultsController objectAtIndexPath:] + 162 Section and cell setup: override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int { // #warning Incomplete method implementation. // Return the number of rows in the section. switch section { case 0: return 1 default: if let realPost:Post = post { return fetchedResultController.sections[0].numberOfObjects } else { return 0 } } } override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! { switch indexPath.section { case 0: let cell = tableView.dequeueReusableCellWithIdentifier(postViewCellIdentifier, forIndexPath: indexPath) as UITableViewCell cell.backgroundColor = lightGrey if let realPost:Post = self.post { cell.textLabel.text = realPost.text } return cell default: let cell = tableView.dequeueReusableCellWithIdentifier(commentCellIdentifier, forIndexPath: indexPath) as UITableViewCell cell.backgroundColor = UIColor.greenColor() let comment = fetchedResultController.objectAtIndexPath(indexPath) as Comment // <---------------------------- :( cell.textLabel.text = comment.text return cell } } FRC: func controllerDidChangeContent(controller: NSFetchedResultsController!) { tableView.reloadData() } func getFetchedResultController() -> NSFetchedResultsController { fetchedResultController = NSFetchedResultsController(fetchRequest: taskFetchRequest(), managedObjectContext: managedObjectContext, sectionNameKeyPath: nil, cacheName: nil) return fetchedResultController } func taskFetchRequest() -> NSFetchRequest { if let realPost:Post = self.post { let fetchRequest = NSFetchRequest(entityName: "Comment") let sortDescriptor = NSSortDescriptor(key: "date", ascending: false) fetchRequest.predicate = NSPredicate(format: "post = %@", realPost) fetchRequest.sortDescriptors = [sortDescriptor] return fetchRequest } else { return NSFetchRequest(entityName: "") } }

    Read the article

  • Displaying Plist data into UItableview

    - by Christien
    I have a plist with Dictionary and numbers of strings per dictionary.show into the url below.and this list of items is in thousands in the plist. I need to display these plist data into the UItableview . How to do this? My Code: - (void)viewWillAppear:(BOOL)animated { // get paths from root direcory NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [documentPaths objectAtIndex:0]; NSString *documentPlistPath = [documentsDirectory stringByAppendingPathComponent:@"p.plist"]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:documentPlistPath]; valueArray = [dict objectForKey:@"title"]; self.mySections=[valueArray copy]; NSLog(@"value array %@",self.mySections); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.mySections count]; } -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *key = [[self.mySections objectAtIndex:section]objectForKey:@"pass"]; return [NSString stringWithFormat:@"%@", key]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 5; } - (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]; } // Configure the cell... NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; cell.textLabel.text = [[self.mySections objectAtIndex:row] objectForKey:@"title"]; cell.detailTextLabel.text=[[self.mySections objectAtIndex:section] objectForKey:[allKeys objectAtIndex:1]]; return cell; } Error is 2012-12-17 16:21:07.372 Project[2076:11603] * Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (4) beyond bounds (4)' * First throw call stack: (0x1703052 0x1523d0a 0x16aba78 0x16ab9e9 0x16fcc60 0x1d03a 0x391e0f 0x392589 0x37ddfd 0x38c851 0x337301 0x1704e72 0x277592d 0x277f827 0x2705fa7 0x2707ea6 0x2707580 0x16d79ce 0x166e670 0x163a4f6 0x1639db4 0x1639ccb 0x1505879 0x150593e 0x2f8a9b 0x2158 0x20b5) terminate called throwing an exceptionkill

    Read the article

  • How to Get Search Bar in Tableview to Appear When User Taps Search Icon at the top of sectionIndex s

    - by Gorgando
    I have a tableview with an indexed scrollbar on the right side that shows the letters A-Z and has a magnifying glass icon at the top ({search}). All of the letters in the scrollbar appropriately take the user to the corresponding section except for the magnifying glass, which takes the user to "A" and keeps the searchBar hidden. I just want it to go to the very top of the table so that the searchBar shows up when the user taps the magnifying glass icon in the scroll bar. I've been looking all over for ways to do this, but I can't find any way shy of adding the searchBar to the first tableCell and it's own section, which I'd prefer not to do unless it's the only way. Thanks so much!

    Read the article

  • Assign TableView column binding to a specific core-data object in to-many related entity based on se

    - by snown27
    How would I assign a column of a TableView to be a specific entry in a Core Data entity that is linked to the NSArrayController via a to-many relationship? For example Entity: MovieEntity Attributes: title(NSString), releaseDate(NSDate) Relationship: posters<-->> PosterEntity Entity:PosterEntity Attributes: imageLocation(NSURL), default(BOOL) Relationships: movie<<--> MovieEntity So I have a three column table that I want to display the Poster, Title, and Release Date attributes in, but as one movie could potentially have several different style's of posters how do I get the poster column to only show the one that's marked default? Since the rest of the table is defined in Interface Builder I would prefer to keep it that way for the sake of keeping the code as clean as possible, but if this can only be done programmatically then I'm all ears. I just wanted to give preference in case there's more than one way to skin a cat, so to speak.

    Read the article

  • I am getting the error Wrong type argument to unary minus and Expected ';' before ':' token

    - by James B.
    I am getting the error Wrong type argument to unary minus and Expected ';' before ':' token The error occurs at the - (NSIndexPath *).... line I am really New at this, so if there is anymore info needed, please ask, if you need to see the entire app, please e-mail me @ james at sevenotwo dot com. the app isn't really complicated. it is based on the sample code on Apple's website for the iphonedatacorerecipes code. #pragma mark - #pragma mark Editing rows - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSIndexPath *rowToSelect = indexPath; NSInteger section = indexPath.section; BOOL isEditing = self.editing; // If editing, don't allow notes to be selected // Not editing: Only allow notes to be selected if ((isEditing && section == NOTES_SECTION) || (!isEditing && section != NOTES_SECTION)) { [tableView deselectRowAtIndexPath:indexPath animated:YES]; rowToSelect = nil; } return rowToSelect; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger section = indexPath.section; UIViewController *nextViewController = nil; /* What to do on selection depends on what section the row is in. For Type, Notes, and Instruments, create and push a new view controller of the type appropriate for the next screen. */ switch (section) { case TYPE_SECTION: nextViewController = [[TypeSelectionViewController alloc] initWithStyle:UITableViewStyleGrouped]; ((TypeSelectionViewController *)nextViewController).doctor = doctor; break; case NOTES_SECTION: nextViewController = [[NotesViewController alloc] initWithNibName:@"NotesView" bundle:nil]; ((NotesViewController *)nextViewController).doctor = doctor; break; case INSTRUMENTS_SECTION: nextViewController = [[InstrumentDetailViewController alloc] initWithStyle:UITableViewStyleGrouped]; ((InstrumentDetailViewController *)nextViewController).doctor = doctor; if (indexPath.row < [doctor.instruments count]) { Instrument *instrument = [instruments objectAtIndex:indexPath.row]; ((InstrumentDetailViewController *)nextViewController).instrument = instrument; } break; default: break; } // If we got a new view controller, push it . if (nextViewController) { [self.navigationController pushViewController:nextViewController animated:YES]; [nextViewController release]; } } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCellEditingStyle style = UITableViewCellEditingStyleNone; // Only allow editing in the instruments section. // In the instruments section, the last row (row number equal to the count of instruments) is added automatically (see tableView:cellForRowAtIndexPath:) to provide an insertion cell, so configure that cell for insertion; the other cells are configured for deletion. if (indexPath.section == INSTRUMENTS_SECTION) { // If this is the last item, it's the insertion row. if (indexPath.row == [doctor.instruments count]) { style = UITableViewCellEditingStyleInsert; } else { style = UITableViewCellEditingStyleDelete; } } return style; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { // Only allow deletion, and only in the instruments section if ((editingStyle == UITableViewCellEditingStyleDelete) && (indexPath.section == INSTRUMENTS_SECTION)) { // Remove the corresponding instrument object from the doctor's instrument list and delete the appropriate table view cell. Instrument *instrument = [instruments objectAtIndex:indexPath.row]; [doctor removeInstrumentsObject:instrument]; [instruments removeObject:instrument]; NSManagedObjectContext *context = instrument.managedObjectContext; [context deleteObject:instrument]; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; } }

    Read the article

  • Objective-C woes: cellForRowAtIndexPath crashes.

    - by Mr. McPepperNuts
    I want to the user to be able to search for a record in a DB. The fetch and the results returned work perfectly. I am having a hard time setting the UItableview to display the result tho. The application continually crashes at cellForRowAtIndexPath. Please, someone help before I have a heart attack over here. Thank you. @implementation SearchViewController @synthesize mySearchBar; @synthesize textToSearchFor; @synthesize myGlobalSearchObject; @synthesize results; @synthesize tableView; @synthesize tempString; #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; } #pragma mark - #pragma mark Table View - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //handle selection; push view } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ /* if(nullResulSearch == TRUE){ return 1; }else { return[results count]; } */ return[results count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; // Test hack to display multiple rows. } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Search Cell Identifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease]; } NSLog(@"TEMPSTRING %@", tempString); cell.textLabel.text = tempString; return cell; } #pragma mark - #pragma mark Memory management - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; } - (void)viewDidUnload { self.tableView = nil; } - (void)dealloc { [results release]; [mySearchBar release]; [textToSearchFor release]; [myGlobalSearchObject release]; [super dealloc]; } #pragma mark - #pragma mark Search Function & Fetch Controller - (NSManagedObject *)SearchDatabaseForText:(NSString *)passdTextToSearchFor{ NSManagedObject *searchObj; UndergroundBaseballAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext; NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == [c]%@", passdTextToSearchFor]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [request setSortDescriptors:sortDescriptors]; [request setEntity: entity]; [request setPredicate: predicate]; NSError *error; results = [managedObjectContext executeFetchRequest:request error:&error]; if([results count] == 0){ NSLog(@"No results found"); searchObj = nil; nullResulSearch == TRUE; }else{ if ([[[results objectAtIndex:0] name] caseInsensitiveCompare:passdTextToSearchFor] == 0) { NSLog(@"results %@", [[results objectAtIndex:0] name]); searchObj = [results objectAtIndex:0]; nullResulSearch == FALSE; }else{ NSLog(@"No results found"); searchObj = nil; nullResulSearch == TRUE; } } [tableView reloadData]; [request release]; [sortDescriptors release]; return searchObj; } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ textToSearchFor = mySearchBar.text; NSLog(@"textToSearchFor: %@", textToSearchFor); myGlobalSearchObject = [self SearchDatabaseForText:textToSearchFor]; NSLog(@"myGlobalSearchObject: %@", myGlobalSearchObject); tempString = [myGlobalSearchObject valueForKey:@"name"]; NSLog(@"tempString: %@", tempString); } @end *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UILongPressGestureRecognizer isEqualToString:]: unrecognized selector sent to instance 0x3d46c20'

    Read the article

  • Why doe my UITableView only show two rows of each section?

    - by Mike Owens
    I have a UITableView and when I build it only two rows will be displayed. Each section has more than two cells to be displayed, I am confused since they are all done the same?`#import #import "Store.h" import "VideoViewController.h" @implementation Store @synthesize listData; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [self createTableData]; [super viewDidLoad]; } (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 { //self.listData = nil; //[super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } pragma mark - pragma mark Table View Data Source Methods // Customize the number of sections in the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [videoSections count]; } //Get number of rows -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.listData count]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *StoreTableIdentifier = @"StoreTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:StoreTableIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StoreTableIdentifier] autorelease]; } cell.textLabel.text = [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"]; //Change font and color of tableView cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.textLabel.font=[UIFont fontWithName:@"Georgia" size:16.0]; cell.textLabel.textColor = [UIColor brownColor]; return cell; } -(NSString *)tableView: (UITableView *)tableView titleForHeaderInSection: (NSInteger) section { return [videoSections objectAtIndex:section]; } -(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { VideoViewController *videoViewController = [[VideoViewController alloc] initWithNibName: @"VideoViewController" bundle:nil]; videoViewController.detailURL = [[NSURL alloc] initWithString: [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"url"]]; videoViewController.title = [[[listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] objectForKey:@"name"]; [self.navigationController pushViewController:videoViewController animated:YES]; [videoViewController release]; } pragma mark Table View Methods //Data in table cell -(void) createTableData { NSMutableArray *beginningVideos; NSMutableArray *intermediateVideos; videoSections = [[NSMutableArray alloc] initWithObjects: @"Beginning Videos", @"Intermediate Videos", nil]; beginningVideos = [[NSMutableArray alloc] init]; intermediateVideos = [[NSMutableArray alloc] init]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Shirts", @"name", @"http://www.andalee.com/iPhoneVideos/testMovie.m4v", @"url", nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Posters", @"name", @"http://devimages.apple.com/iphone/samples/bipbopall.html", @"url", nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Stickers",@"name", @"http://www.andalee.com/iPhoneVideos/mov.MOV",@"url",nil]]; [beginningVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Egyptian",@"name", @"http://www.andalee.com/iPhoneVideos/2ndMovie.MOV",@"url",nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Drum Solo", @"name", @"http://www.andalee.com", @"url", nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Veil", @"name", @"http://www.andalee.com", @"url", nil]]; [intermediateVideos addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:@"Three Quarter Shimmy",@"name", @"http://www.andalee.com", @"url",nil]]; listData = [[NSMutableArray alloc] initWithObjects:beginningVideos, intermediateVideos, nil]; [beginningVideos release]; [intermediateVideos release]; } (void)dealloc { [listData release]; [videoSections release]; [super dealloc]; } @end `

    Read the article

  • "didChangeSection:" NSfetchedResultsController delegate method not being called

    - by robenk
    I have a standard split view controller, with a detail view and a table view. Pressing a button in the detail view can cause the an object to change its placement in the table view's ordering. This works fine, as long as the resulting ordering change doesn't result in a section being added or removed. I.e. an object can change it's ordering in a section or switch from one section to another. Those ordering changes work correctly without problems. But, if the object tries to move to a section that doesn't exist yet, or is the last object to leave a section (therefore requiring the section its leaving to be removed), then the application crashes. NSFetchedResultsControllerDelegate has methods to handle sections being added and removed that should be called in those cases. But those delegate methods aren't being called for some reason. The code in question, is boilerplate: - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { NSLog(@"willChangeContent"); [self.tableView beginUpdates]; } - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { NSLog(@"didChangeSection"); switch(type) { case NSFetchedResultsChangeInsert: [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; } } - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { NSLog(@"didChangeObject"); UITableView *tableView = self.tableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeUpdate: [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; break; case NSFetchedResultsChangeMove: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade]; break; } } - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { NSLog(@"didChangeContent"); [self.tableView endUpdates]; [detailViewController.reminderView update]; } Starting the application, and then causing the last object to leave a section results in the following output: 2011-01-08 23:40:18.910 Reminders[54647:207] willChangeContent 2011-01-08 23:40:18.912 Reminders[54647:207] didChangeObject 2011-01-08 23:40:18.914 Reminders[54647:207] didChangeContent 2011-01-08 23:40:18.915 Reminders[54647:207] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1145.66/UITableView.m:825 2011-01-08 23:40:18.917 Reminders[54647:207] Serious application error. Exception was caught during Core Data change processing: Invalid update: invalid number of sections. The number of sections contained in the table view after the update (5) must be equal to the number of sections contained in the table view before the update (6), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted). with userInfo (null) As you can see, "willChangeContent", "didChangeObject" (moving the object in question), and "didChangeContent" were all called properly. Based on the Apple's NSFetchedResultsControllerDelegate documentation "didChangeSection" should have been called before "didChangeObject", which would have prevented the exception causing the crash. So I guess the question is how do I assure that didChangeSection gets called? Thanks in advance for any help!

    Read the article

  • UITableViewCell selected subview ghosts

    - by Jonathan Cohen
    Hi all, I'm learning about the iPhone SDK and have an interesting exception with UITableViewCell subview management when a finger is pressed on some rows. The table is used to assign sounds to hand gestures -- swiping the phone in one of 3 directions triggers the sound to play. Selecting a row displays an action sheet with 4 options for sound assignment: left, down, right, and cancel. Sounds can be mapped to one, two, or three directions so any cell can have one of seven states: left, down, right, left and down, left and right, down and right, or left down and right. If a row is mapped to any of these seven states, a corresponding arrow or arrows are displayed within the bounds of the row as a subview. Arrows come and go as they should in a given screen and when scrolling around. However, after scrolling to a new batch of rows, only when I press my finger down on some (but not all) rows, does an arrow magically appear in the selected state background. When I lift my finger off the row, and the action sheet appears, the arrow disappears. After pressing any of the four buttons, I can't replicate this anymore. But it's really disorienting and confusing to see this arrow flash on screen because the selected row isn't assigned to anything. What haven't I thought to look into here? All my table code is pasted below and this is a screencast of the problem: http://www.screencast.com/users/JonathanGCohen/folders/Jing/media/d483fe31-05b5-4c24-ab4d-70de4ff3a0bf Am I managing my subviews wrong or is there a selected state property I'm missing? Something else? Should I have included any more information in this post to make things clearer? Thank you!! #pragma mark - #pragma mark Table - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ([categories count] > 0) ? [categories count] : 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([categories count] == 0) return 0; NSMutableString *key = [categories objectAtIndex:section]; NSMutableArray *nameSection = [categoriesSounds objectForKey:key]; return [nameSection count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *nameSection = [categoriesSounds objectForKey:key]; static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SectionsTableIdentifier]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; NSString *soundOfType = [[sound objectAtIndex: row] objectAtIndex: 1]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease]; } cell.textLabel.text = [[nameSection objectAtIndex:row] objectAtIndex: 0]; NSUInteger soundSection = [[[sound objectAtIndex: row] objectAtIndex: 2] integerValue]; NSUInteger soundRow = [[[sound objectAtIndex: row] objectAtIndex: 3] integerValue]; NSUInteger leftRow = [leftOldIndexPath row]; NSUInteger leftSection = [leftOldIndexPath section]; if (soundRow == leftRow && soundSection == leftSection && leftOldIndexPath !=nil){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeft]; selectedSoundLeft.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeft]; } NSUInteger downRow = [downOldIndexPath row]; NSUInteger downSection = [downOldIndexPath section]; if (soundRow == downRow && soundSection == downSection && downOldIndexPath !=nil){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundDown]; selectedSoundDown.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundDown]; } NSUInteger rightRow = [rightOldIndexPath row]; NSUInteger rightSection = [rightOldIndexPath section]; if (soundRow == rightRow && soundSection == rightSection && rightOldIndexPath !=nil){ [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundRight]; selectedSoundRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundRight]; } // combos if (soundRow == leftRow && soundRow == downRow && soundSection == leftSection && soundSection == downSection){ [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndDown]; selectedSoundLeftAndDown.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndDown]; } if (soundRow == leftRow && soundRow == rightRow && soundSection == leftSection && soundSection == rightSection){ [selectedSoundLeft removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndRight]; selectedSoundLeftAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndRight]; } if (soundRow == downRow && soundRow == rightRow && soundSection == downSection && soundSection == rightSection){ [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundDownAndRight]; selectedSoundDownAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundDownAndRight]; } if (soundRow == leftRow && soundRow == downRow && soundRow == rightRow && soundSection == leftSection && soundSection == downSection && soundSection == rightSection){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndDownAndRight]; selectedSoundLeftAndDownAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndDownAndRight]; } [indexPath retain]; return cell; } - (NSMutableString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ([categories count] == 0) return nil; NSMutableString *key = [categories objectAtIndex:section]; if (key == UITableViewIndexSearch) return nil; return key; } - (NSMutableArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if (isSearching) return nil; return categories; } - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { [table reloadData]; [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [search resignFirstResponder]; if (isSearching == YES && [search.text length] != 0 ){ searched = YES; } search.text = @""; isSearching = NO; [tableView reloadData]; [indexPath retain]; [indexPath retain]; return indexPath; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [table reloadData]; selectedIndexPath = indexPath; [table reloadData]; NSInteger section = [indexPath section]; NSInteger row = [indexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; [indexPath retain]; [indexPath retain]; NSMutableString *title = [NSMutableString stringWithString: @"Assign Gesture for "]; NSMutableString *soundFeedback = [NSMutableString stringWithString: (@"%@", soundName)]; [title appendString: soundFeedback]; UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:(@"%@", title) delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle: nil otherButtonTitles:@"Left",@"Down",@"Right",nil]; action.actionSheetStyle = UIActionSheetStyleDefault; [action showInView:self.view]; [action release]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger section = [selectedIndexPath section]; NSInteger row = [selectedIndexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; NSString *soundOfType = [[sound objectAtIndex: row] objectAtIndex: 1]; NSUInteger soundSection = [[[sound objectAtIndex: row] objectAtIndex: 2] integerValue]; NSUInteger soundRow = [[[sound objectAtIndex: row] objectAtIndex: 3] integerValue]; NSLog(@"sound row is %i", soundRow); NSLog(@"sound section is row is %i", soundSection); typedef enum { kLeftButton = 0, kDownButton, kRightButton, kCancelButton } gesture; switch (buttonIndex) { //Left case kLeftButton: showLeft.text = soundName; left = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:left], &soundNegZ); AudioServicesPlaySystemSound (soundNegZ); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; leftIndexSection = [NSNumber numberWithInteger:section]; leftIndexRow = [NSNumber numberWithInteger:row]; NSInteger leftSection = [leftIndexSection integerValue]; NSInteger leftRow = [leftIndexRow integerValue]; NSString *leftKey = [categories objectAtIndex: leftSection]; NSArray *leftSound = [categoriesSounds objectForKey:leftKey]; NSInteger leftSoundSection = [[[leftSound objectAtIndex: leftRow] objectAtIndex: 2] integerValue]; NSInteger leftSoundRow = [[[leftSound objectAtIndex: leftRow] objectAtIndex: 3] integerValue]; leftOldIndexPath = [NSIndexPath indexPathForRow:leftSoundRow inSection:leftSoundSection]; break; //Down case kDownButton: showDown.text = soundName; down = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:down], &soundNegX); AudioServicesPlaySystemSound (soundNegX); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; downIndexSection = [NSNumber numberWithInteger:section]; downIndexRow = [NSNumber numberWithInteger:row]; NSInteger downSection = [downIndexSection integerValue]; NSInteger downRow = [downIndexRow integerValue]; NSString *downKey = [categories objectAtIndex: downSection]; NSArray *downSound = [categoriesSounds objectForKey:downKey]; NSInteger downSoundSection = [[[downSound objectAtIndex: downRow] objectAtIndex: 2] integerValue]; NSInteger downSoundRow = [[[downSound objectAtIndex: downRow] objectAtIndex: 3] integerValue]; downOldIndexPath = [NSIndexPath indexPathForRow:downSoundRow inSection:downSoundSection]; break; //Right case kRightButton: showRight.text = soundName; right = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:right], &soundPosX); AudioServicesPlaySystemSound (soundPosX); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; rightIndexSection = [NSNumber numberWithInteger:section]; rightIndexRow = [NSNumber numberWithInteger:row]; NSInteger rightSection = [rightIndexSection integerValue]; NSInteger rightRow = [rightIndexRow integerValue]; NSString *rightKey = [categories objectAtIndex: rightSection]; NSArray *rightSound = [categoriesSounds objectForKey:rightKey]; NSInteger rightSoundSection = [[[rightSound objectAtIndex: rightRow] objectAtIndex: 2] integerValue]; NSInteger rightSoundRow = [[[rightSound objectAtIndex: rightRow] objectAtIndex: 3] integerValue]; rightOldIndexPath = [NSIndexPath indexPathForRow:rightSoundRow inSection:rightSoundSection]; break; case kCancelButton: [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; break; default: break; } UITableViewCell *viewCell = [table cellForRowAtIndexPath: selectedIndexPath]; NSArray *subviews = viewCell.subviews; for (UIView *cellView in subviews){ cellView.alpha = 1; } [table reloadData]; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSMutableString *)title atIndex:(NSInteger)index { NSMutableString *category = [categories objectAtIndex:index]; if (category == UITableViewIndexSearch) { [tableView setContentOffset:CGPointZero animated:NO]; return NSNotFound; } else return index; }

    Read the article

  • Can you add a UITableViewController's TableView to another View?

    - by Dan Harrelson
    I've inserted a UITableViewController and it's corresponding UITableView into a simple IB document. The goal is to include the UITableView inside of a parent UIWindow (or UIView) with other "stuff" (anything really) adorning the table. Here's what that might look like in Interface Builder. http://danharrelson.com/images/skitch/iphone-tableview-3-20090701-205535.png I've tried this numerous times and always get to the same place. Build a working subclass of UITableViewController filled with data Customize the UTableView and it's cells including tap targets Add the newly created UITableViewController into an IB document Drag the UITableView out of the UITableViewController and into the main UIView Wire up the UITableViewController to the UITableView Note: adding the UITableViewController in code results in the same problem When running the app in the iPhone emulator or on a device the table displays correctly, but crashes the first time you try and interact with it. A scroll, a tap, anything crashes the app. This seems to be a delegate problem, like the UITableView doesn't know how to communicate back to the UITableViewController, but I have no idea how to correct the problem. So far I have been able to get by by customizing the tableHeaderView to get layouts that suffice, but I'd really prefer to have the other technique work.

    Read the article

  • EXC_BAD_ACCESS error on a UITableView with ARC?

    - by Arnaud Drizard
    I am building a simple app with a custom bar tab which loads the content of the ViewController from a UITableView located in another ViewController. However, every time I try to scroll on the tableview, I get an exc_bad_access error. I enabled NSzombies and guard malloc to get more info on the issue. In the console I get: "message sent to deallocated instance 0x19182f20" and after profiling I get: # Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller 56 0x19182f20 FirstTabBarViewController Zombie -1 00:16.613.309 0 UIKit -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging] Here is a bit of the code of the ViewController in which the error occurs: .h file: #import <UIKit/UIKit.h> #import "DataController.h" @interface FirstTabBarViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { IBOutlet UITableView* tabBarTable; } @property (strong, nonatomic) IBOutlet UIView *mainView; @property (strong, nonatomic) IBOutlet UITableView *tabBarTable; @property (nonatomic, strong) DataController *messageDataController; @end .m file: #import "FirstTabBarViewController.h" #import "DataController.h" @interface FirstTabBarViewController () @end @implementation FirstTabBarViewController @synthesize tabBarTable=_tabBarTable; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)awakeFromNib { [super awakeFromNib]; self.messageDataController=[[DataController alloc] init]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.messageDataController countOfList]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"mainCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }; NSString *expenseAtIndex = [self.messageDataController objectInListAtIndex:indexPath.row]; [[cell textLabel] setText:expenseAtIndex]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return NO; } @end This FirstTabBarViewController is loaded in the MainViewController with the following custom segue: #import "customTabBarSegue.h" #import "MainViewController.h" @implementation customTabBarSegue -(void) perform { MainViewController *src= (MainViewController *) [self sourceViewController]; UIViewController *dst=(UIViewController *)[self destinationViewController]; for (UIView *view in src.placeholderView.subviews){ [view removeFromSuperview]; } src.currentViewController =dst; [src.placeholderView addSubview:dst.view]; } @end The Datacontroller class is just a simple NSMutableArray containing strings. I am using ARC so I don't understand where the memory management error comes from. Does anybody have a clue? Any help much appreciated ;) Thanks!!

    Read the article

  • UITableView: Juxtaposing row, header, and footer insertions/deletions

    - by jdandrea
    Consider a very simple UITableView with one of two states. First state: One (overall) table footer One section containing two rows, a section header, and a section footer Second state: No table footer One section containing four rows and no section header/footer In both cases, each row is essentially one of four possible UITableViewCell objects, each containing its own UITextField. We don't even bother with reuse or caching, since we're only dealing with four known cells in this case. They've been created in an accompanying XIB, so we already have them all wired up and ready to go. Now consider we want to toggle between the two states. Sounds easy enough. Let's suppose our view controller's right bar button item provides the toggling support. We'll also track the current state with an ivar and enumeration. To be explicit for a sec, here's how one might go from state 1 to 2. (Presume we handle the bar button item's title as well.) In short, we want to clear out our table's footer view, then insert the third and fourth rows. We batch this inside an update block like so: // Brute forced references to the third and fourth rows in section 0 NSUInteger row02[] = {0, 2}; NSUInteger row03[] = {0, 3}; [self.tableView beginUpdates]; state = tableStateTwo; // 'internal' iVar, not a property self.tableView.tableFooterView = nil; [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects: [NSIndexPath indexPathWithIndexes:row02 length:2], [NSIndexPath indexPathWithIndexes:row03 length:2], nil] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; For the reverse, we want to reassign the table footer view (which, like the cells, is in the XIB ready and waiting), and remove the last two rows: // Use row02 and row03 from earlier snippet [self.tableView beginUpdates]; state = tableStateOne; self.tableView.tableFooterView = theTableFooterView; [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects: [NSIndexPath indexPathWithIndexes:row02 length:2], [NSIndexPath indexPathWithIndexes:row03 length:2], nil] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; Now, when the table asks for rows, it's very cut and dry. The first two cells are the same in both cases. Only the last two appear/disappear depending on the state. The state ivar is consulted when the Table View asks for things like number of rows in a section, height for header/footer in a section, or view for header/footer in a section. This last bit is also where I'm running into trouble. Using the above logic, section 0's header/footer does not disappear. Specifically, the footer stays below the inserted rows, but the header now overlays the topmost row. If we switch back to state one, the section footer is removed, but the section header remains. How about using [self.tableView reloadData] then? Sure, why not. We take care not to use it inside the update block, per Apple's advisement, and simply add it after endUpdates. This time, good news! The section 0 header/footer disappears. :) However ... Toggling back to state one results in a most exquisite mess! The section 0 header returns, only to overlay the first row once again (instead of appear above it). The section 0 footer is placed below the last row just fine, but the overall table footer - now reinstated - overlays the section footer. Waaaaaah … now what? Just to be sure, let's toggle back to state two again. Yep, that looks fine. Coming back to state one? Yecccch. I also tried sprinkling in a few other stunts like using reloadSections:withRowAnimation:, but that only serves to make things worse. NSRange range = {0, 1}; NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range]; ... [self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationFade]; Case in point: If we invoke reloadSections... just before the end of the update block, changing to state two hides the first two rows from view, even though the space they would otherwise occupy remains. Switching back to state one returns section 0's header/footer to normal, but those first two rows remain invisible. Case two: Moving reloadSections... to just after the update block but before reloadData results in all rows becoming invisible! (I refer to the row as being invisible because, during tracing, tableView:cellForRowAtIndexPath: is returning bona-fide cell objects for those rows.) Case three: Moving reloadSections... after tableView:cellForRowAtIndexPath: brings us a bit closer, but the section 0 header/footer never returns when switching back to state one. Hmm. Perhaps it's a faux pas using both reloadSections... and reloadData, based on what I'm seeing at trace-time, which brings us to: Case four: Replacing reloadData with reloadSections... outright. All cells in state two disappear. All cells in state one remain missing as well (though the space is kept). So much for that theory. :) Tracing through the code, the cell and view objects, as well as the section heights, are all where they should be at the opportune times. They just aren't rendering sanely. So, how to crack this case? Clues welcome/appreciated!

    Read the article

  • UITableView not getting populated

    - by jayshree430
    Hi. I have a peculiar problem. I created a normal Objective c class called SampleTable. I then extended UITableView instead of NSObject. Then in the initWithFrame constructor i initialized the table. I also made a NSMutableArray object for the datasource. I also conformed UITableViewDelegate and UITableViewDatasource. I have overridden the necessary methods also. Now i made an object of this class in another class, and added the object as a subview. The tableView is getting drawn according to the CGRectMake() coordinates i gave to the initWithFrame constructor. But it is not getting populated with the data. I dnt know what the problem is . Can plz someone help me. SampleTable.h #import @interface SampleTable : UITableView { NSMutableArray *ItemArray; } @property (nonatomic,retain) NSMutableArray *ItemArray; -(NSMutableArray *) displayItemArray; @end SampleTable.m #import "SampleTable.h" @implementation SampleTable @synthesize ItemArray; -(id)initWithFrame:(CGRect)frm { [super initWithFrame:frm]; self.delegate=self; self.dataSource=self; [self reloadData]; return self; } -(NSMutableArray *) displayItemArray { if(ItemArray==nil) { ItemArray=[[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; } return ItemArray; } (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [ItemArray count]; } (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]; [cell autorelease]; } NSString *temp=[self.ItemArray objectAtIndex:indexPath.row]; cell.textLabel.text = temp; return cell; } (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"didselect"); } -(void) dealloc { [ItemArray release]; [super dealloc]; } @end

    Read the article

  • Position a UIView at the middle of a UITableView with CGRectZero frame

    - by Thomas Joulin
    Hi, I have a UITableViewController view a UITableView that I alloc/init with a frame of CGRectZero : self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped]; I want to add a view at the middle of the tableView (a loading view with a UIActivityIndicatorView and a UILabel), but I don't know how to position it, since I don't know the tableView frame. x = (self.tableview.frame.size.width - loadingView.frame.size.width) / 2.0; y = (self.tableview.frame.size.height - loadingView.frame.size.height) / 2.0; [loadingView setCenter:CGPointMake(x, y)]; I did init my tableView with CGRectZero frame so it can take the whole place available on screen (which it did), but I thought its frame would update or something. Any ideas ? Thanks !

    Read the article

  • cant populate cells with an array when i have loaded a second UITableViewController

    - by richard Stephenson
    hi there, im very new to iphone programming, im creating my first app, (a world cup one) the first view is a table view. the cell text label is filled with an array, so it shows all the groups (group a, B, c,ect) then when you select a group, it pulls on another UITableViewcontroller, but whatever i do i cant set the text label of the cells (e.g france,mexico,south africa, etc. infact nothin i do to the cellForRowAtIndexPath makes a difference , could someone tell me what im doing wrong please Thanks `here is my code for the view controller #import "GroupADetailViewController.h" @implementation GroupADetailViewController @synthesize groupLabel = _groupLabel; @synthesize groupADetail = _groupADetail; @synthesize teamsInGroupA; #pragma mark Memory management - (void)dealloc { [_groupADetail release]; [_groupLabel release]; [super dealloc]; } #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; // Set the number label to show the number data teamsInGroupA = [[NSArray alloc]initWithObjects:@"France",@"Mexico",@"Uruguay",@"South Africa",nil]; NSLog(@"loaded"); // Set the title to also show the number data [[self navigationItem]setTitle:@"Group A"]; //[[self navigationItem]cell.textLabel.text:@"test"]; //[[self navigationItem] setTitle[NSString String } - (void)viewDidUnload { [self setgroupLabel:nil]; } #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView { // Return the number of sections in the table view return 1; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in a specific section // Since we only have one section, just return the number of rows in the table return 4; NSLog:("count is %d",[teamsInGroupA count]); } - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { static NSString *cellIdentifier2 = @"Cell2"; // Reuse an existing cell if one is available for reuse UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2]; // If no cell was available, create a new one if (cell == nil) { NSLog(@"no cell, creating"); cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } NSLog(@"cell already there"); // Configure the cell to show the data for this row //[[cell textLabel]setText:[NSString string //[[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]]; //NSUInteger row = [indexPath row]; //[cell setText:[[teamsInGroupA objectAtIndex:indexPath:row]retain]]; //cell.textLabel.text:@"Test" [[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]]; return cell; } @end #import "GroupADetailViewController.h" @implementation GroupADetailViewController @synthesize groupLabel = _groupLabel; @synthesize groupADetail = _groupADetail; @synthesize teamsInGroupA; #pragma mark Memory management - (void)dealloc { [_groupADetail release]; [_groupLabel release]; [super dealloc]; } #pragma mark View lifecycle - (void)viewDidLoad { [super viewDidLoad]; // Set the number label to show the number data teamsInGroupA = [[NSArray alloc]initWithObjects:@"France",@"Mexico",@"Uruguay",@"South Africa",nil]; NSLog(@"loaded"); // Set the title to also show the number data [[self navigationItem]setTitle:@"Group A"]; //[[self navigationItem]cell.textLabel.text:@"test"]; //[[self navigationItem] setTitle[NSString String } - (void)viewDidUnload { [self setgroupLabel:nil]; } #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView { // Return the number of sections in the table view return 1; } - (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in a specific section // Since we only have one section, just return the number of rows in the table return 4; NSLog:("count is %d",[teamsInGroupA count]); } - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath { static NSString *cellIdentifier2 = @"Cell2"; // Reuse an existing cell if one is available for reuse UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier2]; // If no cell was available, create a new one if (cell == nil) { NSLog(@"no cell, creating"); cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier2] autorelease]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } NSLog(@"cell already there"); // Configure the cell to show the data for this row //[[cell textLabel]setText:[NSString string //[[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]]; //NSUInteger row = [indexPath row]; //[cell setText:[[teamsInGroupA objectAtIndex:indexPath:row]retain]]; //cell.textLabel.text:@"Test" [[cell textLabel]setText:[teamsInGroupA objectAtIndex:indexPath.row]]; return cell; } @end

    Read the article

  • Adding NavigationControl to a TabBar Application containing UITableViews

    - by kungfuslippers
    Hi, I'm new to iPhone dev and wanted to get advice on the general design pattern / guide for putting a certain kind of app together. I'm trying to build a TabBar type application. One of the tabs needs to display a TableView and selecting a cell from within the table view will do something else - maybe show another table view or a web page. I need a Navigation Bar to be able to take me back from the table view/web page. The approach I've taken so far is to: Create an app based around UITabBarController as the rootcontroller i.e. @interface MyAppDelegate : NSObject <UIApplicationDelegate> { IBOutlet UIWindow *window; IBOutlet UITabBarController *rootController; } Create a load of UIViewController derived classes and associated NIBs and wire everything up in IB so when I run the app I get the basic tabs working. I then take the UIViewController derived class and modify it to the following: @interface MyViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> { } and I add the delegate methods to the implementation of MyViewController - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 2; } - (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]; } if (indexPath.row == 0) { cell.textLabel.text = @"Mummy"; } else { cell.textLabel.text = @"Daddy"; } return cell; } Go back to IB , open MyViewController.xib and drop a UITableView onto it. Set the Files Owner to be MyViewController and then set the delegate and datasource of the UITableView to be MyViewController. If I run the app now, I get the table view appearing with mummy and daddy working nicely. So far so good. The question is how do I go about incorporating a Navigation Bar into my current code for when I implement: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath() { // get row selected NSUInteger row = [indexPath row]; if (row == 0) { // Show another table } else if (row == 1) { // Show a web view } } Do I drop a NavigationBar UI control onto MyControllerView.xib ? Should I create it programmatically? Should I be using a UINavigationController somewhere ? I've tried dropping a NavigationBar onto my MyControllerView.xib in IB but its not shown when I run the app, only the TableView is displayed.

    Read the article

  • Singleton array deallocated? EXC_BAD_ACCESS

    - by lclaud
    Ok, so I have this singleton object and in it is an array that needs to be shown in a tableview. The thing is that it deallocates and after the first show, i get EXC_BAD_ACCESS in cellForRowAtIndexPath - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [[dataBase shareddataBase].dateActive count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"celula"]; int i; i=indexPath.row; if (cell==nil) { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"celula"]; } count sent to dealocated instance of CFArray .. in cellForRowAtIndexPath.. WHAT is deallocating it? why? it's declarea as an NSMutableArray and has a (nonatomic,retain) property defined .. if ((i<[[dataBase shareddataBase].dateActive count])&&(i>=0)) { NSDictionary *d=[[dataBase shareddataBase].dateActive objectAtIndex:i]; cell.textLabel.text=[d objectForKey:@"detaliu"]; } return cell; }

    Read the article

  • NSCFType keeps occurring, something is not being released?

    - by user1493543
    I'm attempting to delete files from the documents directory using a tableview/array combination. For some reason, my NSString pointing to the Documents directory path is being converted to a NSCFType (which after some research, I understand is happening because a variable is not being released). Because of this, the application crashes at the line NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:temp]; claiming that NSCFType cannot recognize the method stringByAppendingPathComponent. I would appreciate if someone could help me out (I hope I have explained this clearly enough). - (void) tableView: (UITableView *) tableView commitEditingStyle: (UITableViewCellEditingStyle) editingStyle forRowAtIndexPath: (NSIndexPath *) indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSString *temp = [directoryContent objectAtIndex:indexPath.row]; NSLog(temp); NSString *lastPath = [documentsDirectory stringByAppendingPathComponent:temp]; [[NSFileManager defaultManager] removeItemAtPath:lastPath error:nil]; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); documentsDirectory = [paths objectAtIndex:0]; directoryContent = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil] retain]; //tableview handling below }

    Read the article

  • My application crashing Please help me out.

    - by kiran kumar
    My Application get crashing ... its loading data of all the cities... and when i click its displaying my detailed view controller.... when iam getting back from my controller... and selecting another city my application get crashed.. Please help me out. To get idea i am pasting my code. #import "CityNameViewController.h" #import "Cities.h" #import "XMLParser.h" #import "PartyTemperature_AppDelegate.h" #import "CityEventViewController.h" @implementation CityNameViewController //@synthesize aCities; @synthesize appDelegate; @synthesize currentIndex; @synthesize aCities; /* // 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 { [super viewDidLoad]; self.title=@"Cities"; appDelegate=(PartyTemperature_AppDelegate *)[[UIApplication sharedApplication]delegate]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (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 [appDelegate.cityListArray count]; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 95.0f; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; cell.textLabel.textColor = [[[UIColor alloc] initWithRed:0.2 green:0.2 blue:0.6 alpha:1] autorelease]; cell.detailTextLabel.textColor = [UIColor blackColor]; cell.detailTextLabel.font=[UIFont systemFontOfSize:10]; if (indexPath.row %2 == 1) { cell.backgroundColor = [[[UIColor alloc] initWithRed:0.87f green:0.87f blue:0.87f alpha:1.0f] autorelease]; } else { cell.backgroundColor = [[[UIColor alloc] initWithRed:0.97f green:0.97f blue:0.97f alpha:1.0f] autorelease]; } } // 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; cell.selectionStyle= UITableViewCellSelectionStyleBlue; // cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; cell.backgroundColor=[UIColor blueColor]; } // aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row]; // cell.textLabel.text=aCities.city_Name; cell.textLabel.text=[[appDelegate.cityListArray objectAtIndex:indexPath.row]city_Name]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ //http://compliantbox.com/party_temperature/citysearch.php?city=Amsterdam&latitude=52.366125&longitude=4.899171 NSString *url; aCities=[appDelegate.cityListArray objectAtIndex:indexPath.row]; if ([appDelegate.cityListArray count]>0){ url=@"http://compliantbox.com/party_temperature/citysearch.php?city="; url=[url stringByAppendingString:aCities.city_Name]; url=[url stringByAppendingString:@"&latitude=52.366125&longitude=4.899171"]; NSLog(@"url value is %@",url); [self parseCityName:[[NSURL alloc]initWithString:url]]; } } -(void)parseCityName:(NSURL *)url{ NSXMLParser *xmlParser=[[NSXMLParser alloc]initWithContentsOfURL:url]; XMLParser *parser=[[XMLParser alloc] initXMLParser]; [xmlParser setDelegate:parser]; BOOL success; success=[xmlParser parse]; if (success) { NSLog(@"Sucessfully parsed"); CityEventViewController *cityEventViewController=[[CityEventViewController alloc]initWithNibName:@"CityEventViewController" bundle:nil]; cityEventViewController.index=currentIndex; [self.navigationController pushViewController:cityEventViewController animated:YES]; [cityEventViewController release]; cityEventViewController=nil; } else { NSLog(@"Try it Idoit"); UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert!" message:@"Event Not In Radius" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } } - (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 { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [aCities release]; [super dealloc]; } @end And the error is * Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSMutableArray objectAtIndex:]: index 1 beyond bounds for empty array' ** Call stack at first throw:

    Read the article

  • Content Alignment Issue in UITableView cell

    - by OhhMee
    Please see the image attached. I don't understand why it's going outside. I've also attached code snippet for tableView. - (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]; // cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; } // Configure the cell. hNode* dCell = [array objectAtIndex:[indexPath row]]; cell.textLabel.text = @"Message"; cell.detailTextLabel.text = [NSString stringWithFormat:@"%@",[dCell contents]]; cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; cell.detailTextLabel.numberOfLines = 0; [[cell imageView] setImage:[UIImage imageNamed:@"user.png"]]; return cell; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath { return 60; } Where could be the issue?

    Read the article

  • UITableViewController executes delate functions before network request finishes

    - by user1543132
    I'm having trouble trying to populate a UITableView with the results of a network request. It seems that my code is alright as it works perfectly when my network is speedy, however, when it's not, the function - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath- still executes, which results in a bad access error. I presume that this is because the array that the aforesaid function attempts to utilize has not been populated. This brings me to my question: Is there anyway that I can have the UITableView delegate methods delayed to avoid this? - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"AlbumsCell"; //UITableViewCell *basicCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; AlbumsCell *cell = (AlbumsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { **// Here is where the Thread 1: EXC_BAD_ACCESS (code=2 address=0x8)** cell = [[[AlbumsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } Album *album = [_albums objectAtIndex:[indexPath row]]; [cell setAlbum:album]; return cell; }

    Read the article

  • App is getting run in iOS 5.1.1 but crashed in iOS 6.1.3

    - by Jekil Patel
    I have implemented below code but app has been crashed in iPad with iOS version 6.1.3,while running perfectly in iPad with iOS version 5.1.1. when I am scrolling table view continuously it is crashed in ios version 6.1.3. what could be the issue. The implemented delegate and data source methods for the table view are as given below. #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 [UserList count]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell = nil; if (cell == nil) { // cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } UIImageView *imgViweback; imgViweback = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,0,0)]; imgViweback.image = [UIImage imageNamed:@"1scr-Student List Tab BG.png"]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 32, 32)]; UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(12, 5, 50, 50)]; UILabel *lblName = [[UILabel alloc] initWithFrame:CGRectMake(110, 5, 200, 40)]; //cell.backgroundColor = [UIColor clearColor]; //cell.alpha = 0.5f; CountSelected = 0; flagQuizEnabled = NO; if ([[[checkedImages objectAtIndex:indexPath.row] valueForKey:@"checked"] isEqualToString:@"NO"]) { // cell.imageView.image = [UIImage imageNamed:@"Unchecked.png"]; //imageView.image = [UIImage imageNamed:@"Unchecked.png"]; } else { //imageView.image = [UIImage imageNamed:@"Checked.png"]; } NSString *pathTillApp=[[self getImagePath] stringByDeletingLastPathComponent]; NSLog(@"Path Till App %@",pathTillApp); NSString *makePath=[NSString stringWithFormat:@"%@%@",pathTillApp,[[UserList objectAtIndex:indexPath.row ]valueForKey:@"ImagePath"]]; NSLog(@"makepath=%@",makePath); imageView1.image = [UIImage imageWithContentsOfFile:makePath]; [cell.contentView insertSubview:imgViweback atIndex:0]; [cell.contentView insertSubview:imageView atIndex:0]; [cell.contentView insertSubview:imageView1 atIndex:2]; lblName.text =[NSString stringWithFormat:@"%@ %@",[[UserList objectAtIndex:indexPath.row] valueForKey:@"FirstName"],[[UserList objectAtIndex:indexPath.row] valueForKey:@"LastName"]]; lblName.backgroundColor = [UIColor clearColor]; lblName.font = [UIFont boldSystemFontOfSize:22.0f]; //lblName.font = [UIFont fontWithName:@"HelveticaNeue Heavy" size:22.0f]; lblName.font = [UIFont fontWithName:@"Chalkboard SE" size:22.0f]; [cell.contentView insertSubview:lblName atIndex:3]; [imgViweback release]; [imageView release]; [imageView1 release]; [lblName release]; imgViweback = nil; imageView = nil; imageView1 = nil; lblName = nil; //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; return cell; } #pragma mark - Table view delegate -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Values : %@", Val); }

    Read the article

  • Grafting LINQ onto C# 2 library

    - by P Daddy
    I'm writing a data access layer. It will have C# 2 and C# 3 clients, so I'm compiling against the 2.0 framework. Although encouraging the use of stored procedures, I'm still trying to provide a fairly complete ability to perform ad-hoc queries. I have this working fairly well, already. For the convenience of C# 3 clients, I'm trying to provide as much compatibility with LINQ query syntax as I can. Jon Skeet noticed that LINQ query expressions are duck typed, so I don't have to have an IQueryable and IQueryProvider (or IEnumerable<T>) to use them. I just have to provide methods with the correct signatures. So I got Select, Where, OrderBy, OrderByDescending, ThenBy, and ThenByDescending working. Where I need help are with Join and GroupJoin. I've got them working, but only for one join. A brief compilable example of what I have is this: // .NET 2.0 doesn't define the Func<...> delegates, so let's define some workalikes delegate TResult FakeFunc<T, TResult>(T arg); delegate TResult FakeFunc<T1, T2, TResult>(T1 arg1, T2 arg2); abstract class Projection{ public static Condition operator==(Projection a, Projection b){ return new EqualsCondition(a, b); } public static Condition operator!=(Projection a, Projection b){ throw new NotImplementedException(); } } class ColumnProjection : Projection{ readonly Table table; readonly string columnName; public ColumnProjection(Table table, string columnName){ this.table = table; this.columnName = columnName; } } abstract class Condition{} class EqualsCondition : Condition{ readonly Projection a; readonly Projection b; public EqualsCondition(Projection a, Projection b){ this.a = a; this.b = b; } } class TableView{ readonly Table table; readonly Projection[] projections; public TableView(Table table, Projection[] projections){ this.table = table; this.projections = projections; } } class Table{ public Projection this[string columnName]{ get{return new ColumnProjection(this, columnName);} } public TableView Select(params Projection[] projections){ return new TableView(this, projections); } public TableView Select(FakeFunc<Table, Projection[]> projections){ return new TableView(this, projections(this)); } public Table Join(Table other, Condition condition){ return new JoinedTable(this, other, condition); } public TableView Join(Table inner, FakeFunc<Table, Projection> outerKeySelector, FakeFunc<Table, Projection> innerKeySelector, FakeFunc<Table, Table, Projection[]> resultSelector){ Table join = new JoinedTable(this, inner, new EqualsCondition(outerKeySelector(this), innerKeySelector(inner))); return join.Select(resultSelector(this, inner)); } } class JoinedTable : Table{ readonly Table left; readonly Table right; readonly Condition condition; public JoinedTable(Table left, Table right, Condition condition){ this.left = left; this.right = right; this.condition = condition; } } This allows me to use a fairly decent syntax in C# 2: Table table1 = new Table(); Table table2 = new Table(); TableView result = table1 .Join(table2, table1["ID"] == table2["ID"]) .Select(table1["ID"], table2["Description"]); But an even nicer syntax in C# 3: TableView result = from t1 in table1 join t2 in table2 on t1["ID"] equals t2["ID"] select new[]{t1["ID"], t2["Description"]}; This works well and gives me identical results to the first case. The problem is if I want to join in a third table. TableView result = from t1 in table1 join t2 in table2 on t1["ID"] equals t2["ID"] join t3 in table3 on t1["ID"] equals t3["ID"] select new[]{t1["ID"], t2["Description"], t3["Foo"]}; Now I get an error (Cannot implicitly convert type 'AnonymousType#1' to 'Projection[]'), presumably because the second join is trying to join the third table to an anonymous type containing the first two tables. This anonymous type, of course, doesn't have a Join method. Any hints on how I can do this?

    Read the article

  • UISearchDisplayController "shouldReloadTableForSearchString return NO" reloads table

    - by Jeena
    Why does my UISearchDisplayController show "No results" even if the shouldReloadTableForSearchString method returns NO? Shouldn't it just do nothing and stay black? How can I prevent it from doing so? #import "RootViewController.h" #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 { if (tableView == self.searchDisplayController.searchResultsTableView) { return 0; } return 10; } // 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:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } // Configure the cell. cell.textLabel.text = [NSString stringWithFormat:@"row %d", indexPath.row]; return cell; } #pragma mark SearchController stuff - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { return NO; } - (void)dealloc { [super dealloc]; } @end

    Read the article

  • Opening a View with a Table without a NavigationController

    - by Ken
    Hiya, I'm pretty new to developing with Cocoa Touch/XCode and I came across a problem. I'm making a sort of RSS reader for a newssite and I have 5 views of tables navigated with 5 tabs in a TabBarController. If someone selects a newsitem I want another view to open showing the complete newsitem. My problem is that it won't work. This is my code: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection(NSInteger)section{ return [[[self rssParser]rssItems]count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"rssItemCell"]; if(nil == cell){ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"rssItemCell"]autorelease]; } cell.textLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title]; cell.detailTextLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]description]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[self appDelegate] setCurrentlySelectedBlogItem:[[[self rssParser]rssItems]objectAtIndex:indexPath.row]]; [self.appDelegate loadNewsDetails]; } And it calls this method in my delegate: -(void)loadNewsDetails{ [[self rootController]pushViewController:detailController animated:YES]; } Please tell me what I'm doing wrong. BTW I do not want to use a NavigationController, just the tabbar I'm using. Thanks in advance, Ken

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >