Update main view with change in tableView subview - objective-c

I have a tableView sub view on my Main view controller. Here's a screenshot: https://www.dropbox.com/s/mp5r9eiv8tg3fmj/Screenshot%202015-02-03%2018.58.24.png?dl=0
I want to update the "remaining" labels when a row is either inserted or deleted. The problem comes when I call my "setLabels" method in controller didChangeObject: delete and insertRowAtIndexPaths. With this (https://www.dropbox.com/s/fcj8h3a03pfud6x/Screenshot%202015-02-04%2019.11.46.png?dl=0 ) implementation the labels only update when the next cycle comes. (If i add one, nothing will happen until I add another or delete one. I'm left with the label values that correspond to the tableView before the most recent change. Always one step behind)
I added an NSLog to verify the method is being called (it is) so I have no idea why my labels won't update till controllerWillChangeContent is called for a second time.
PS: my set labels method is simple. It uses my "getSum" method which gets the sum of an entities attribute and sets the label

Related

NSTable/OutlineView: Edit textfield in a row without selecting the row

Context:
I have an NSOutlineView that acts like a source list, but does not use the actual source list highlighting style. (Imagine the sidebar in the Finder.)
This outlineView has only two levels: 1) "groups" and 2) "subitems". There is no additional nesting --- again, just like the source list in the Finder.
What I Want:
The top-level "group" rows in my OutlineView are NSTableCellViews with a single NSTextField. I would like my users to be able to edit the text in this textField (to rename the group) WITHOUT allowing them to select the entire group row in the OutlineView.
So far, I've not found a way to do this. If I prevent selection of group rows in my delegate for the OutlineView, it is not possible to edit the textfield. When I allow selection of the group rows, then I can get the textfield to edit just like any other.
Short of subclassing things and handling mouse events myself, is there a simple way to do this? Must a row in an NSTableView always be selected before textFields in that row can be edited?
I think it will work to use a custom subclass of NSOutlineView in which you override -validateProposedFirstResponder:forEvent: to return true if the proposed first responder is in a group row. Return whatever super returns for any other proposed first responder.
You can determine which row the proposed first responder is in by calling -rowForView:.
See this blog post from the Apple engineer who wrote the view-based table view stuff.

Handling tableview cell selection from other view controllers

I have a tableView with custom table cells which displays a list of sayings. While selecting a cell (say "saying1") from the tableView, the cell will get selected and will moves to next view controller for showing an explanation of selected saying. In that view controller two buttons "Previous" and "Next" are there for navigating to previous and next saying. So user may select next button for seeing next saying (say "saying2"). But the problem here is, In this stage when i navigate back to my tableview, the cell selected will be "saying1" not "saying2".
In order to solve this problem, i collected the currently selected sayings ("saying2's") index from array (ie,index will be 1) and passed it to the previous tableView through segue and converted that value into NSIndexpath. After this step i don't know what to do. Please help me in solving this.
You can specifically select a cell by calling following method present in UITableView class :
selectRowAtIndexPath:animated:scrollPosition:
refere to following link : https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/selectRowAtIndexPath:animated:scrollPosition:

How to implement numberOfRowsInSection to add a Button in UITableView?

I have a UITableView with gets populated from a backing array every time cellForRowAtIndexPath is called. The user can either go Back (via the nav bar) or they must submit the tableview's dataset to a server. Our GUI team wants the interface designed with a 'Done' button as the last cell in the table row in order to submit the dataset. Right now, numberOfRowsInSection is returning [myArray count] and I could conceivably alter the backing array with a "ghost" record for the done button, or simply return [myArray count] + 1 and catch the mis-matched array count in cellForRowAtIndexPath. Both ways, however, seem like trouble down the road. What's the best way to implement this?
Either put the button in the footer for the tableview, or mess with the row count. I've used both methods, just depends how much that last cell needs to look like the rest of the rows (or not look like them, in the case of using the footer)

Adding rows to a UITable from an array

I have a UITable, and class who is it's datasource and delegate. The class has a property called logItemsArray which contains a number of objects which are used as data for a row (customer name, date added etc...) (the cells have a special class to which I pass these objects and it returns a cell).
I also have a method called loadNextLogEvents which loads some data from a web server and adds items into the logItemsAraay (it automatically loads the data for the next 100 rows).
This method is called once from the viewWillApear method and also from a button to load the next events.
The table view's dataSource numberOfRowsInTable returns the count of the logItemsArray.
The thing is: How do I "update" the table from the loadNextLogEvents to use the new data to load cells (the array is updated so both the numberOfRowsInTable and the cellForRowAtIndexPath method will return the desired result of new row, I just need to trigger them!
Use this:
[tableView reloadData];

Get state of UISwitch in custom UITableViewCell's

I am using a custom tableviewcell in one of my view's. I have decided to add a UISwitch to this cell to enable the user to delete multiple row's at once.
Normally when the user selects a row and taps my delete button I have a UIAlert pop up for confirmation and after that the alert clickedButtonAtIndex method handles the outcome. In that method I get the indexpath ( [self.myTableView indexPathForSelectedRow] ) and delete (or not) accordingly.
So basically as the title states instead of using the indexPath to fall into my delete statement, I need to check to see if self.myTableView.myCell.mySwitch.on is TRUE. Can anyone point me in the right direction for doing this? I will need to iterate through all rows in the tableview and for each row where the state is on it needs to be removed.
Thanks.
you should iterate through your cells using a nested loop ( or a single loop if you have only one section) and cellForRowAtIndexPath:.if you see a cell's switch.on = TRUE save it's indexPath in an array by calling indexPathForCell:. after you're done iterating through your cells, call deleteRowsAtIndexPaths:withRowAnimation: with the array previously created.