iOS: selecting option returns null first time, not second time - iphone

I have an iOS application where you select an option before you log in. The way it works is that you click on the button that says "Select", then it takes you to a UITableViewController which shows you the options, you select the option, and it takes you back to the previous menu with the text replaced with your selection (and a hidden ID saved, too).
During the update of the information (which takes place in tableView:didSelectRowAtIndexPath:) I call NSLog on the object. The first time I call it, it returns null (BUT for some reason the text still changes!) and the second time I call it, it works! Why doesn't it work the first time????
Thanks

Do you put the NSLog line before the previous view push back code ?

The variable was named incorrectly. I don't know why XCode didn't just tell me this instead of giving me an EXC_BAD_ACCESS, but that's what happened.

Related

Process page, or be notified that elements are present even if page not fully loaded

The page I'm using watir-webdriver on will often not load completely for maybe like a minute because of the many external scripts I'm loading/using. This of course means that I have to wait needlessly for a minute when I could have performed the checks I wanted to in 10 seconds after the browser I'm controlling (Firefox) started loading the page.
I noticed that even though my target elements become immediately available in the page, the browser.div(:id => 'some_id').present? method hangs until the page is fully loaded. I noticed that if I press on the stop button in the browser window, watir will immediately continue successfully with my tests (the present? method un-hangs). Is there a way to avoid this behavior of the present? method and be able to tell that my target elements are present without having to wait for the page to fully load?
I've experienced this issue before as well. The method I employed, which rides on the idea you mentioned about hitting the stop button, is as follows:
begin
browser.wait_until{browser.div(:id => 'some_id').present?}
rescue
browser.send_keys :escape
end
expect(browser.div(:id=> 'some_id').present?).to be true
This, by default, gives that div 30 seconds to appear (you can insert a smaller value then 30 if you prefer), otherwise it causes watir to hit 'escape' which will stop any remaining background page loading and resume the test.
.present?
As I understand it checks to see if an element exists AND is visible.
What I would suggest you try, is
.exists?
This will simply check that the element exists, and doesnt care if its visible or not.
Just for reference, there is also a
.visible?
Which just makes sure the item is visible, though I dont ever use that one.

Robotium : Is there a way to check for an activity to NOT exist?

I'm automating an app that shows some overlay messages anywhere on the app for several scenarios, such as app installed for the first time etc. (I'm fairly new to Robotium too.)
The overlay displays a text that goes away by swiping or clicking on it. Also, there are different types of these overlays with different unique text on it. (let's call it Activity A)
I wanted to create a robust test case that handles this case gracefully. From the test's perspective we won't know that the activity A will be present all the time. But I want to recover from the scenario if it does, by writing a method that I can call any time. Currently, the tearDown method gets called since my expected activity name doesn't match.
Also, even if the activity A exists, there are other predefined overlay texts too. So, if I use solo.waitForText("abc") to check for text "abc", I may see the overlay 2 with the text "pqr" instead.
So I was looking for a way to automate this, and I can't use solo.assertCurrentActivity() or solo.waitForActivity methods as they just stop the execution after the first failure.
So any guidance is appreciated!
All the waitFor methods return a boolean. So you can use waitForActivity() exactly as you want to. If the Activity doesn't exist it will return false.
You can check which Activity is current:
Activity current = solo.getCurrentActivity();

How do I disable copy, paste and select functions in a UIWebView that is showing a PDF file?

My app has a UIWebView that is used for showing a PDF file. The file size is less than 1MB but when the user double taps the screen, the app freezes and crashes a few moments later.
I think that if I disabled the select function, maybe this problem wouldn't occur. How do I do that?
Have a look at the console output. It looks like you are not handling tap events properly. You must have those handlers even if you want to ignore tap events (i.e. do nothing and return).
Here's a good overview of what needs to be done:
http://mithin.in/2009/08/26/detecting-taps-and-events-on-uiwebview-the-right-way/

UISearchBar error when entering Searchbar textbox

I have found a strange error. I have been following this sample:
http://jduff.github.com/2010/03/09/throwing-a-uinavigationcontroller-uitabbarcontroller-and-uisearchbar-together/
I tested it and then tried to roll it in my app. It worked in the sample but not my app. In my app I would SIGABRT or BAD_ACCESS errors whenever I entered the textview inside the searchbar. The main difference was that I placed the Search on the second tab rather than the first. When I changed the taborder on my app to have the search on the first tab's navigation controller, it worked! It seems that unless I first enter the searchbar's textview. The object gets released and if I try to enter it later it fails. Very weird. I don't know enough about the objects here to say what the initialization sequence is but my guess is I need to do more initialization to get it to work.
go through the article in the link once more. especially through the "Setting up the Project" part.
In the article everything is set for the "selected view controller" which is the first one. And you say you implement everything to the second tab. Make sure you didn't implement everything in the first one of your project.
Let me know if this helps. If not I'll figure out something else.

how to solve error EXC_BAD_ACCESS in my application?

I am loading the custom cell on tableView and i return 50 rows in the tableView.
number of some rows are display in the tableview but when scroll the tableview my customcell is not display and I have the error
"EXC_BAD_ACCESS"
and also display following message on the console
"void SendDelegateMessage(NSInvocation*): delegate (webViewDidLayout:) failed to return after waiting 10 seconds. main run loop mode: UITrackingRunLoopMode"
I think you get this error due to your method of making custom cells. When you made the class file for the custom cell in the .m file you released the IBOutlets. Try removing that portion from your code than try.
I had the same problem in an app, and I solved that problem this way. Maybe this solution will work for you too.
The best way to detect zombies is:
in the Groups and Files section,
expand the Executables section
and right click on your app name and
choose Get Info
select the Arguments tab on the top and then add a new entry in the Variables to be set in the environment section. Name the new variable to NSZombieEnabled and set its value to YES.
After this you will have information in console on which released objects you make calls.
This typically means that you have asked the program to look at a memory area that you don't have access to, which usually means you have run off the end of an array, or something.
If you are running in debug mode, the stack trace will probably give you more clues. Open up the debug console.
You should also use NSZombieEnabled, it usually helps. It shows you which deallocated object was accessed. Be sure to disable it after you use it because using this, no memory is ever released.