Set Selected Cell on load NSTableViewCell - swift

Iv got a mac application that uses a table view on the left side of the window as the navigation, and then another table view on the right that shows the relevant information.
I do this by just checking what cell is selected on the left table view and use that to update the information on the right.
The problem is when the table views load they dont have a row selected, the selected row shows up as -1 (AKA nothing) i need the table view to have a row selected when the view loads, not just after someone selects it. Kinda like the finder window, when you open the application it has a row already selected.
And no i dont want to just change the background color of the cell so it looks selected when the app opens, because that wont fix the -1 problem.

You cans select a row programmatically using the API on NSTableView:
func selectRowIndexes(_ indexes: NSIndexSet,
byExtendingSelection extend: Bool)
Let us say, you want to pre select the 0th row, then you can need to call the above API as in viewDidLoad method:
tableView. selectRowIndexes(NSIndexSet(index:0) byExtendingSelection:NO)

Related

Set voiceover's focus on a specific table cell in uitableview (UIAccessibility)

I have a UITableView that I have scroll to the bottom as soon as the user adds another element/table cell to it. For the screen this works fine, because the user can see the cell they just added at the bottom of the table. But when running my app using VoiceOver, the first UITableCell to get focused and read is the top cell that's visible on the screen.
I want to set it so that the cell that gets focused and then read as soon as this UITableView appears is the very last cell in the table. How do I do this? It seems like it would be very simple but I can't figure it out.
Here's what I tried so far (in cellForRowAtIndexPath):
if (cellJustAdded && indexPath.row == [array count]-1) {
cell.accessibilityElementIsFocused = YES; //obviously this does not work
}
but I don't think you can use accessibilityElementIsFocused like that.
When you want VoiceOver to select a certain element you can post an accessibility notification using UIAccessibilityPostNotification( ... );.
Depending on if it's a major (complete screen) change or a minor (layout only) change you should post either
UIAccessibilityScreenChangedNotification (complete change)
UIAccessibilityLayoutChangedNotification (small change)
In both cases the optional argument is the element that VoiceOver should move to.
So after having added the new cell to your table view you would call
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification,
yourNewCellThatShouldHaveFocus);

getting some values in the table view rows in an iphone app

hii every one
i am new to iphone, i have done a sample data entry project in that i am saving data into the sqlite then displaying the saved data in the table view , & then on click of each row of the table it will go to other page (grouped table view where i am displying detailed data) now i have the table view like this
on click of each row it will go to detailed view like this
then on click of back button it ill come back to data list screen but it ill add some other data into the screen like this
i am using reload data in view will apear ,, is that causing this problem?it works fine if i comment that n try,,
can any one help me
thanx in advance
When you add new row in the table upon back button press, you can either add a new row in the table using
insertRowsAtIndexPaths:withRowAnimation:
or update your array (adding this extra row) with the help of which you show the rows and then reload the table view. Because when you reload your table view, its datasource methods will be called again and then you need to return updated number of sections, rows and cell's
Check your array values in didSelectRowAtIndexPath delegate whether you have different arrays or not.
If yes then use [yourArray objectAtIndex:indexPath.row]

How to use first responder to keep only one cell selected at the maximum in a view with multiple table views?

I have a scrollview which has several table views as sub views...
say that I have selected a cell in one of the sub views. Now when I select a cell from another view, the cell I selected previously should not be highlighted.
How do I do this? I know I can do this using the first responder, but I am not sure how to do it.
Would anyone be able to help me out in this?
Thanks
From the apple interface guidlines:
Always provide feedback when users select a list item. Users expect a table row to highlight briefly when they tap a selectable item in it. After tapping, users expect an immediate action to occur: Either a new view appears or the row displays a checkmark to indicate that the item has been selected or enabled.
In rare cases, a row might remain highlighted when secondary details or controls related to the row item are displayed in the same screen. However, this is not encouraged because it is difficult to display simultaneously a list of choices, a selected item, and related details or controls without creating an uncomfortably crowded layout.
I don't think apple will approve an app that leaves a row highlighted (I had an app reject for that very reason). You should perform an action and then immediately unhighlight it. In some rare cases you can leave it highlighted while showing a related view.
However, if you store the current cell you have selected, you can call -deselectRowAtIndexPath:animated: on the tableview to deselect a row.

"show 20 more messages" button in uitableview

I am newbie to iphone programming. I doing an mail like app in that i have to show inbox information in table view and at the final of dragging i should need "show 20 more messages" button. is there possibility of showing that?
if please can you provide with me a codes.
Regards,
sathish
Sure, you just have to manage it manually:
Add one extra row to your table view.
In tableView:cellForRowAtIndexPath:, if the indexPath corresponds to the last possible row (which is the extra row you added), create a cell that represents the button.
In tableView:didSelectRowAtIndexPath:, if the indexPath corresponds to the last possible row, have your datasource load the additional data and send a insertRowsAtIndexPaths:withRowAnimation: to your table view.

iPhone Dev: Get more data functionality in twitter iPhone clients?

I'm building an app (not necessarily a twitter client) and I'm trying to figure out how developers create the buttons above and below a table view where a user presses them to either reload newer data or reload older data into a table view. Does anyone know of any tutorials out there that does this or know of an easy way?
If you want fixed buttons, you can just make your table view not use the full screen and add the buttons in the space. If you want the buttons to scroll with the table view, you can add a header or footer view to the table and put your buttons inside that.
Check the Three20 project. I believe there's a tableview there that does that.
It's actually not that hard to add inline buttons to a tableview. First you check and see if there's actually more data to show. If so, you want to add 1 to the number of rows returned from the datasource. When asked to draw that last row you return a cell that contains "Press for more" caption as well as a hidden spinner instead of the standard cell that shows your normal data.
If the user presses that last button the table view handler turns on the spinner then fires off a network event. Once the network request completes the data is processed and added to the same tableview datasource that was used to draw the first table.
Now all you have to do is tell the tableview to reload itself and the new data will show up. If you want to limit the amount of data shown you can prune out N number of items from the head of the datasource before redrawing so the memory-use stays manageable.