I am trying to automate some tests of my ipad application.
I have a scrollview which contains a custom view.
The custom view overwrites the drawRect and has a TapRecognizer.
The custom view is created into the code and I have set this properties
myView.userInteractionEnabled = YES;
[myView setIsAccessibilityElement:YES];
[myView setAccessibilityLabel:#"myView"];
The custom view is added to the scrollview with
[myScrollView addSubview:myView];
Everything works smooth both on device and on simulator: tapping on the view, the tap recognizer callback is called and the custom view can draw something at the tap point.
I would automate the view test and then I need to simulate user's taps on myView.
In the uiautomation script I have something like this:
myView = circuitScrollView.elements()[0];
myView.logElement();
myView.tapWithOptions({x:56, y:576});
to simulate a user tap at position x=56 and y=576.
Nothing happens, it seems that myView doesn't receive any tap (just in case, I play a sound into the TapRecognizer but it has never been sounded).
I have tryed this too:
myView.tap();
no success.
Any idea ?
Thank you in advance.
Fab.
This may be of some use to you. I wrote a test that taps certain x/y coordinates. Rather than touching the scroll view try tapping the window as demonstrated below.
To do so I wrote:
var window = UIATarget.localTarget();
window.tap({x:x_co , y:y_co});
x_co and y_co were my coordinates.
Hope this helps.
Maybe myView = circuitScrollView.elements()["myView"] might help instead of myView = circuitScrollView.elements()[0]; ?
Maybe your custom view is not the first element in the element tree of your circuitScrollView...
Related
I have added two swipe gesture recognizers (swipe left and swipe right) to my UITableView. After that my table view has stopped scrolling. At the same time -(void)didSelectRowAtIndex works fine.
What might be the problem?
All I did is drag-and-dropped Swipe Gesture Recognizers from objects library onto my UITableView.
If I remove them, my table starts to scroll again.
UPD:
This happens after upgrading to Xcode 4.5. There is no such problem in older versions of Xcode.
To avoid this behaviour - add UIGestureRecognizers programatically, not in IB.
just try bellow code may this help you....
write bellow code in viewDidLoad: method
UISwipeGestureRecognizer *swipeGestureObjectImg = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(yourSlideOpen_Clicked:)] autorelease];//yourSlideOpen_Clicked is method name where you doing something
swipeGestureObjectImg.numberOfTouchesRequired = 1;
swipeGestureObjectImg.direction = (UISwipeGestureRecognizerDirectionLeft);
[yourView addGestureRecognizer:swipeGestureObjectImg];
UISwipeGestureRecognizer *swipeGestureRightObjectImg = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(yourSlideClose_Clicked:)] autorelease];//yourSlideClose_Clicked is method name where you doing something
swipeGestureRightObjectImg.numberOfTouchesRequired = 1;
swipeGestureRightObjectImg.direction = (UISwipeGestureRecognizerDirectionRight);
[yourView addGestureRecognizer:swipeGestureRightObjectImg];
if here tableview is subview of UIView class then use above code otherwise just try "youtTableview" insted of "yourView"
i hope this help you...
:)
set property of gesture recognizer cancelsTouchesInView = NO
I had the same issue:
I used to drag my TabGestureRecognizer directly onto the storyboard instead of creating them through code. With iOS6 this now seems to break scrolling.
I prefer adding views, gestures, etc directly onto the storyboard instead of through code.
You can still do this but with two changes:
1) Referencing Outlet Collections
Right-click the GestureRecognizer which is visible to you within the scene's dock.
Clear the section Referencing Outlet Collections
2) Attach the GestureRecognizer to the related view through code
Create an outlet for your GestureRecognizer
Add the following line within the viewDidLoad method:
[self.tableView addGestureRecognizer:_tabGesture];
I faced this same problem and I solved it by linking the gesture recognizer to the view instead of to the table view.
Show the storyboard.
Show the connections inspector.
Show the document outline.
Create new link at "Referencing Outlet Collections" between gesture recognizer and view node under the view controller.
Regards.
Pedro.
I am working on a custom controller. I want to create a slider, to choose between more options. The problem is that when I touch the button I want to it doesn't call my touchesBegan method. But if I press in any other part of my view, it works. How can I get my button to move?
Thanks.
The UIButton is capturing the touch events. if you try this
myButton.userInteractionEnabled = NO;
Then it will no longer consume the touch events but it will also no longer fire the onTouchUpInside event. In this case you process all of the touches in the super view and position the slider button accordingly.
It should drag just fine. This will work for any UIView.
touchesBegan will not work on a UIButton .. for that to work you will have to subclass UIButton and implement touchesBegan
refer this answer for more info https://stackoverflow.com/a/4863734/919545
Why don't you create a custom UIView and avoid using the UIButton class? It is simplier that subclassing UIButto or to set
myButton.userInteractionEnabled = NO;
I need to have a UIButton inside a UITableViewCell, everything works fine except when I touch inside the button and move my finger, the table does not scroll.
I tried to subclass UIButton and in touchesMoved: method send the same message to self.nextResponder, or call touchesCancelled and hope it will pass the touch event to next responder, they both do not work.
Is there any good way to solve this problem? Currently I am adding a UIView on top of the UITableViewCell, and detecting touch events manually, passing result to the button or the rest of the cell respectively, but this is a little bit dirty.
What you can try is setting the delaysContentTouches property of the UITableView to YES.
Additionally you can set the canCancelContentTouches to YES.
If the value of this property is NO, the scroll view does not scroll
regardless of finger movement once the content view starts tracking.
Source: UIScrollView Class Reference
Try:
_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;
The best way is to make a custom cell and do your work neatly.
Check the Apple docs
I'm developing an iPhone app, i have a UIViewController class where some coverflow animations are there and according to design i have some 5 buttons on top of my view each button have an IBAction method on clicking a button i need to display different set of coverflow with different data and the count of coverflow also changes from 1 button action to another. My problem is how can i refresh my page(reload) on click of these buttons, as i know calling explicitly viewDidLoad is a very bad idea, so how can i accomplish this? Any help is appreciated in advance thank you.
The easiest way to get a view to re-draw itself is to call [UIView setNeedsDisplay] or by using [UIView setNeedsDisplayInRect]. This method tells the view that it needs to re-draw itself and it's subviews. However you shouldn't always have to call this. There are other methods that can cause views to redraw themselves. For instance if you add or remove a view to the view hierarchy using [UIView addSubview:] or [UIView removeFromSuperview].
These methods cause the system to call your view's drawInRect: method (assuming you overrode it with custom drawing code). If you did not override this method for custom drawing then it should cause your subviews to receive the same message so that they can get a chance to redraw.
Additional information here. Specifically read the section labeled "The View Drawing Cycle".
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html
Why do you want to reload the page?, if it is because you are changing your view and you want it to be redrawn, you can call:
setNeedsDisplay();
But that is often not needed, as whenever a views bounds change that is called automatically for you.
If there's too much other stuff rather than refreshing/reloading the part of your interest in your viewDidLoad method, you can extract the refreshing part into a private method, say methodA. Every time you click your button, you call that methodA. However I think methodA still need call setNeedsDisplay or re-draw the the part of your interest. Hope it helps.
If your point is to refresh "UIViewController", then:
[self viewDidLoad];
Source: How to refresh UIViewController programmatically?
To Refresh your UIViewController, When Clicking the button >>
Add the below code into your UIButton method,
-(IBAction)button:(id)sender{
[self viewDidLoad];
[self viewWillAppear:YES];
}
Now Build and Run Your Code.
Use function viewWillAppear().This function is called everytime the view is called.
I know this has been talked about a lot. I think I've gone thru every question on this site, and still have not been able to get this working.
I'm new to developing but I have a good sense of what's going on with all of my code. I definitely don't have a lot of experience though, this is my first iPhone app.
I'm making a data entry field that is comprised of multiple UITextFields within a UIScrollView. I'll avoid explaining the other details for now, as it seems its a very basic problem. Without a scrollview, the textfields work perfectly. I can touch the textfield and the keyboard or picker view show up appropriately. When I add the textfields to a scrollview, the scrollview works, but then the text fields don't receive my touches.
Here's the key: When 'User Interaction' is ENABLED, the scrollview works but the textfield touches are NOT registered. When 'User Interaction' is DISABLED, the scrollview doesn't work, but the textfield touches ARE registered and the keyboard/picker pops up.
From the other posts I have seen people creating subclasses and overriding the touches in a separate implementation. I've seen people using custom content views (subviews?), I've seen some solutions that are now obsolete since the APIs have changed in newer versions of the SDK, and I am just completely stuck.
I will leave out my code for now, because maybe there is a solution that someone has without requiring my code. If someone needs to see my code, I will put it up. My app is being written in the 3.1.3 SDK.
If anyone has ANY information that could help, it would be so greatly appreciated.
Here is what worked for me in Xcode 4.3.3.
In the storyboard, select your scrollview. Select Attribute Inspector on the right side. Uncheck Delays Content Touches.
It sounds like you're using IB to do a lot of your UI layout. If you take a programmatic approach you could set-up the following view hierarchy which should work.
Your view controller object managing your scroll view and your text fields should have a UIScrollView object and a UIView object (in addition to any UITextField objects you need). In the loadView method of the view controller class, allocate and initalize the UIView object and add your text fields to it as subviews. At the end of the method, allocate and initalize the UIScrollView object then add the UIView to the UIScrollView as a subview.
As an example, if your UIScrollView object were called scrollView and your UIView object called mainView the following lines at the end of the view controller's loadView method would properly set up the scroll view with the main view with the text fields on it:
scrollView = [[UIScrollView alloc] initWithFrame: [[UIScreen mainScreen] bounds] ];
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.contentSize = mainView.frame.size;
[scrollView addSubview: mainView];
self.view = scrollView;
You may need to enable / disable user interaction for both the scroll view and text fields as necessary.
If possible you might best using different touch mechanisms for each process (scrolling and textfield input).
Maybe you can check the time differential between touch start and end such that you can detect the difference between a drag (scroll) and a tap (text input).
Having said that if you propagate the touches up from the textfields to the scrollview you should be fine. One thing I use is:
[myObject addTarget:self action:#selector(itemTouchedUpInside:) forControlEvents:UIControlEventTouchUpInside];
which passes the object touched so you can identify it and act accordingly.