UICollectionView is not giving right index path when moving into empty section - ios

I've been working with a great bit of code LXReorderableCollectionViewFlowLayout (written by Stan Chang Khin Boon). It allows for moving items around in a UICollectionView
I have a collection view with multiple sections. The sections are using a header with several controls in them. I allow the user to create empty sections and drag items into these sections
I using the collection view to show multiple albums of photos. Each section correlates to a different album. Dragging a photo from "Album 1" to "Album 2" works fine when each album already has items in it.
But, if the album (section) is empty, I can't move objects into that empty section.
I think the problem is with "indexPathForItemAtPoint". This method provides the correct NSIndexPath if the section has items in it. But if it's empty, it always returns section = 0, row = 0.
When I cross the border from section "0" into section "1" the NSIndexPath theIndexPathOfSelectedItem goes to 0,0 (section, row). I would have expected it to go to 1,0.
The problem seems to be with "indexPathForItemAtPoint". It isn't taking into consideration that the section might be empty and just defaults to 0, 0 when I cross the border into a different (and empty) section.
Like I said earlier, if there are items already in section "1" then the indexPath is set correctly.
Any ideas on what I'm doing wrong?

I ended up placing a dummy (but invisible) item in the empty section. When I create a new section, I place a dummy value in the section. I make it invisible so that it doesn't show. Anytime I add a new item OR remove an item from a section I test to make sure that the dummy item is there.
IMPORTANT: If there is at least 1 real item in the section, I remove the dummy value. Otherwise, the collection list tries to draw it.
I'm sure there is a better way of doing this. If you know how, please post a new answer.
Hope this helps.

Related

How does YouTube structure its video screen?

My guess is that, under the actual video, is one table view, which has two sections.
The first section's header includes the video's title and other details and the rows are the related videos. The second section's header has the comment form and the rows are the comments.
How else could this be done? If the related videos, for example, is a distinct table view, then given that its a scroll view, wouldn't it scroll in place instead of scrolling as part of the overall screen?
Open YouTube right click> view page source. Add see the structure
Do this inside a a video page. You could inspect element also if your in chrome. To mouseover certain elements on the page to see their styling
Ctrl+shift+C will change your mouse action from element click to element selection
I think it has two sections
In first section it has title descriptions and other information in header and related videos in rows and in second section it has comments heading and comment text box in header and comments in rows
How to implement it
Create 4 cells two header cells and two rows cells

How to count the number of items and have this sustainable when I add new items?

I am trying to create a Google Spreadsheet which is able to count the number of items, and also be sustainable when I add new items which won't affect the previous result.
The table at the left is the data, and on the right is the result I am looking for Example:
The two items in RED box are newly added, and the yellow cells show the results expected.
Basically, when there is a item is bigger than ZERO, I want it to be counted. However, I don't want the previous result to change when I drag the function across.
I tried to use the combination of =counta and vlookup, but it is not working properly.
Assuming your red box is around B8:E9 then in H3 copied across and down to suit:
=COUNTIFS(C:C,"<>"&0,$B:$B,$G3)
will give the results you show (other than the highlighting). However, two more days of data and one table may get in the way of the other. You might want to relocate one table above the other so each has room to expand - or move one to another sheet which would then require sheet references to be added to the above formula.
I am not clear what issues you have had with whatever combination of =counta and vlookup you have tried.

How to make the following screen on iOS, which UI elements i need to use where?

Screen contains 3 dynamic lists. Screen should be scrollable, but i know the total amount of the items in every list before displaying the UI (no need in infinite scroll)
Cats
Cat1 image + Cat1 label
...
CatN image + CatN label
Button: ADD NEW CAT >
Dogs
Textarea or button with description1
...
Textarea or button with descriptionN
(No button to add a new dog)
Promocode
Textarea or button with promo1
...
Textarea or button with promoN
(Button "+" ) + editText to input promo
Every 3 sections has unique differences in design.
Should i use 3 different collectionviews on this screen? should i add scrollview as the root? Please advice
I already answered in the comment but i'm gonna write down something a bit more complete here.
If you already have all the information you need (which should always be the case) before loading your view, then we're all set.
I suggest a scrollview either of tableview type or collectionview type.
You'd have 3 sections in them?
Since you need different cells (apparently) in each section, you could have 3 different custom cells.
When building your table/collectionview, you would check for the current section
(if tableview.section == 0) //(or 1 or 2)
and load the required cell at that point. Then fill it with relevant information.
To add your button at the end of each section you could have another custom cell that would only load if you're section X and at the last index. That's another inner if
//Inside every section code, you'd check if its the last element of the array.
if (indexPath.row == [yourArray count]-1)
And obviously in your "numberOfRowsInSection" you'd need to add that extra row :
if (section == 0){
return [yourArray count]+1;
}else if (section == 1){
//... repeat for your section1 array
}
So you'd need 3 arrays, one for section 0, one for section 1 and one for section 2. The first one would hold all your cat objects, the second one your dogs, and so on.
Now that will work and maybe look good but I'm not an ios expert either.

How to create a Hierarchical menu in iOS?

In my application, I have a menu that is defined as follows. Each item on the menu is a node that has the following data attributes:
MenuText : (the text that would appear for that item)
isView : Whether this item is a leaf level item or not
subMenus : if isView is false, then there are multiple menu items under this attribute.
Thus, it is a tree structure that can go till any depth. The items in the menu can change periodically and hence the implementation has to be kept flexible. This data is stored in a plist file and read into an NSArray in the code (already implemented).
I now need to create a slide out menu on the left that will be populated by this data hierarchy. I have created the menu pane and added swipe gestures to it, all of which work fine. The menu has to be a collapsible one where clicking on one menu item expands the subViews below it. If the item clicked on is a view, then a new view is loaded on the rest of the screen with appropriate data.
The problem I am facing is the logic to populate the menu (which is a UITableView) from the NSArray data. The following are the two approaches I came up with.
Create a UITableView with as many sections as there are items at the top level of the menu. Then iterate through the menu items recursively. For each menu item that is not a view (i.e. it has subMenus), create a new section with number of rows equal to the number of subMenus under it. When I come across a menu item that is a view and has no further subMenus, add it as a row to the subsection created for the menu one level above it.
Create a menu with one section and as many rows as the number of menu items at the top level. When a menu item is clicked, insert rows under it to represent its sub-menus. When another menu item on the same level is clicked, collapse the previously expanded menu by deleting the inserted rows. When a menu item with no sub menus is clicked, the rest of the screen is populated with data.
I have tried both the approaches and not been able to go beyond the initial steps. For the first method, I understand that I need to add a UITableView as a part of UITableViewCells, which is good, but I need to do that recursively. For the second approach, I need to know the indexPath of each item clicked which can go to many levels.
I would like some suggestions here about which approach I should take and some guidance over how to go about it. Also, if there is any better way to do this, kindly advice. Thanks.
In my opinion, using UINavigationController is the easiest way. You can push as many UITableViews as you want.
If it doesn't fit your design requirement, you can try expandable UITableViews. There are few open sources:
JKExpandTableView
SDNestedTable
iOS-Tree-Component
Thanks for the responses. I ended up doing this using the following control:
Accordion for iOS
It has served my purpose beautifully and I posted it here so that someone with the same requirement may find it.
Take a look at TLIndexPathTools. It has a "Tree" extension that can do this. Try running the Outline sample project. The main task in adapting the sample project would be to write a recursive function to convert your array of nodes into an array of TLIndexPathTreeItem objects. All of the code in the controller:willChangeNode: method is examples of lazy loading and it doesn't sound like you'd need any of that.

Titanium Mobile editable row moves inner row elements

I have a tableView with multiple TableViewRow objects, always 4.
When the edit button is clicked the row can be reordered, which is working.
But when the edit button is clicked the elements inside of a row seem to be moved with margins from left and right.
The items in a row should not be moved, so I was hoping someone could tell me how I can make sure the labels inside a row element are not being moved around when edited.
I have included some images, hoping to clarify my question:
Rows when not edited
Rows when edited
The solution was easy, but I didnt know.
The way to achieve this; Add a view to each row and do NOT set the left or right properties.
This way the delete button and move icon are not pushing the inner view away.
Its a default behavior. I dont think there's any way defined in Titanium API to override the moving of inner elements. So you cannot change this default behavior.

Resources