"No view found for fragment" when scrolling in recylerView with fragment attached to each item - android-fragments

I am trying to display a fragment under each RecylerView item on click and collapse/remove the same if user clicks on it again. I was able to pull this off by following the answer available here https://stackoverflow.com/a/37212091
But the main problem occurs when we try to scroll in the recycler view with all the items expanded (displaying fragment) and intermittently it crashes with below logs. I have tried looking it up and find something similar but nobody had a proper solution for this crash.
java.lang.IllegalArgumentException: No view found for id 0x19 (unknown) for fragment NowFragment{ec5e02f} (7d3220ae-56be-43ad-af1e-804d18b27689) id=0x19}
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:315)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
I found someone facing a similar crash here: Add fragment in RecyclerView.ViewHolder
But there is no concrete solution.
Can anyone please help me to resolve this?

Related

NavigationController and View Hierarchy issue

I have 1 (rootViewController) view controller which is embedded in navigation controller. Then i pushed another view controller (secondViewController), which has search controller in title view. When i am trying search become first responder (Active) i got this in terminal:
Warning: Attempt to present
"AppName.CustomSearchViewController: 0x7face0c20eb0> on
whose view is
not in the window hierarchy!
This happens only in iOS lower than 11. When i embed this second view controller in navigation controller and present it modally all works good, but i need exactly pushing. How can i solve this?
I solved it! I need to make definesPresentationContext false in rootViewController to make it work on another one!

Espresso perform click on button located in fragment

I've got the following problem. I want to test my application with Espresso. Therefore I want to click a button which is part of the "Buttons" fragment, this fragment is located in a frame-layout in the MainActivity.
Ofcourse I can check if the frame-layout is displayed but I can not reach the layout of the fragment which is located into the frame-layout.
So my question is, how can I reach the layout of the fragment into the frame-layout, so I can click on a button into the fragment.
The result at the moment is a NoViewMatchException:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id:...
Thanks in advance!
Edit: The exception shows the view hierarchy
These are the methods I'm calling:
onView(ViewMatchers.withId(R.id.buttons)).check(matches(isDisplayed()));
This is the frame-layout in the MainActivity for the buttons fragment:
onView(withText("LOCATIONS")).perform(click());
The locations buttons is in the Buttons fragment
withId on the button id in stead of withText doesn't make sense.
The question is not very clear. It does not matter which layout you are using. Espresso can locate the element on the view hierarchy. If your case, you're getting NoViewMatchException. That means the view (R.id.buttons) is not there when you're checking.
For debugging, you can add some wait (SystemClock.sleep(2000)) and check if it works.
If that works, you need to write the idling resource to wait for the buttons fragment to appear.

I can't change initial Xcode storyboard view

I'm trying to change my initial view in my storyboard, but, when I change it I get this strange view:
Anyone can tell me why?
Ps: In my project I don't have any tab controllers, so I don't know why there is a tab over there...
Is it possible you are doing a universal app and are looking at the wrong View?
What you have there is a navigation bar in a blank view and probably a message in your messages telling you that you have not got a root view controller.
In the past I have solved this by
a) Restarting XCode.
b) Making a new view, copying and pasting the essential View Controller from my old View and deleting the old View.
c) Checking in my summary that the view I think is being talked to actually is the one specified.
d) Looking at my storyboard and checking that the viewcontroller is specified in the object inspector as "Is initial View Controller" by checking the box.

Disable UIPageViewController when ModalViewController opened

I am totaly new to this site, but I already like it :-)
I found it by searching for a question about the UIPageViewController.
I have a normal UIPageViewController App, in which I open a ModalViewController for setting up some settings...
Now the Problem: :-)
If I click on the done Button on the right side of the ModalView, to dismiss it, the PageViewController turnes the page, because he thinks that he is meant by that click ;-)
Can I disable the PageViewController GestureRecognizer as long as I have a ModalView opened?
Is there a method to disable and later his recognizer?
thank you for your help in advance...
cu Matze
It seems odd that your UIPageViewController would steal touches from a modal view presented over it. Unless, perhaps, you are embedding the modal view within the content of the UIPageViewController?
To answer your question -- you can easily disable the page view controller's gesture recognizers by enumerating its gestureRecognizers property (an NSArray):
for (UIGestureRecognizer *gr in [self.pageViewController gestureRecognizers]) {
[gr setEnabled:NO];
}
Re-enable them later with setEnabled:YES.
UPDATE:
In iOS 6 UIPageViewControllerTransitionStyleScroll has been added. UIPageViewControllers that use this transition style return no gesture recognisers in the array returned by gestureRecognizers. Presumably page view controllers with this transition style use an underlying, private UIScrollView instance (it behaves just like a UIScrollView with paging enabled), although I haven't checked this.

UINavigationController with UITableView in modal popup (on iPad)

Short Version:
"How do you get a simple UITable drill down UINavigationController-styled non-full-screen modal dialog on the iPad?"
Long version:
I have a very specific set of requirements that I can't seem to get working...
I have a functioning iPad program that that needs to pop up a non-full-screen modal view. This modal needs to have a navigation controller and a simple drill-down table that displays a detailed view that I can have edit some values related to the selected item in the table.
Of course I am looking to have the regular "Back" and "Delete" buttons in the Navigation Bar.
I can handle the detailed view, what I am having issues with:
Non-full-screen popup (mine is
always full screen no matter what I
try).
The Navigation controller will not display the Table View I tell it to and the navigation bar does not even have the title I assigned to it in IB.
I can't seem to get any of this working. If anyone has a step by step example of how to do this, that would be great,
~Eric
P.S. I am not afraid of doing this 100% programmatically, but all the examples I have been trying to follow (and failing at extending to my problem) use IB.
As for the fullscreen issue, you need to set modalPresentationStyle to UIModalPresentationFormSheet or UIModalPresentationPageSheet on the controller you want to present modally. I'm not sure of a way to do this through IB.
As for your navigation controller/table view, I think more information is needed to provide an answer.

Resources