ViewController-Xib calling randomly - random

In my App,i want to call xib's randomly when the next button is clicked each time.
Is it possible to do with arc4random() method ?
Please share your ideas.

Related

Page animation with visual feedback on drag gesture

I was wondering, I'm currently using a slide in and out page transition when the user presses a Next of Previous button on the appbar.
( concept: going through a set of articles inside a selected category )
This all looks great, I'm also able add the drag / flick gesture listeners to trigger this page transition... so no problems there.
But now I wanted to add the final part, when the user starts the drag / flick gesture, show this visually so that the page follows the gesture and 'slides' out of frame.
But how to do this? An example would be great :)
But there is also a small extra thing, I don't want the user to always do a full drag... so if we are over 2/3 of the screen, auto start the page transition IF the gesture stops ( so the user lifts up his finger )
So I would like to create a nice reading experience that shows the gesture visualy and performs the page transition...
You can check the following link: https://stackoverflow.com/a/9915016/1565574
In the ManipulationCompleted you'll be able to detect the GestureType and take an action there.
And I found that link: https://stackoverflow.com/a/4342558/1565574 (using the GestureService)
I first started with the DragFlickBehavior from #LocalJoost and it actually worked great!
But in the end I switched to a headerless pivot! Works also great!

NSTimer for count down among view controllers

\I have a view controller which starts a count down timer and updates a button label according to it.The problem is that when the user leaves the view and come back i do not want to restart the timer o continue from the paused time.What would be the best way to active it?
Making the timer in app delegate and post notification to the this view controller.Since the other view controllers do not need it they do not need to listen to any notification.The problem is that i have to make sure that the timer has run down to 0 to enable the button os it means when the view is loaded again i need to wait for the notification at least 1 second to make sure that he time is really up.The problem is what to show during this period on the button label.
If the view controller was a tab bar item i would be no problem but it is a pushedv view contller so it is released when the user taps on back.
Just create a singleton object for managing your timer(s). You can create it from appdelegate.
You can get remaining time from that object anytime you want (firedate - datenow). So you do not need to work with notifications. It is also not good idea to send a notification in every second, which is not used by your view, when it is not allocated. When your view is allocated / comes to screen can ask that object every second the remaining time and updates his label or some subviews etc. You can implement it easily with a NSTimer object.
You can also place a bool variable in that singleton object, which indicates, if firedate reached. Or check remaining time < 1 . So your view check the value of the variable while is allocating/showing then you can decide to activate or deactivate your button.

Stop UIPickerViewAnimation

Is there a way to instantly stop the animation of rolling UIPIckerView or UIDatePicker on button click.
Look into - (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component
Since Picker can only show limited number of results at a time. You can implement an algorithm to determine what is in the middle of the result when this method is called. It gets called every time a new option appears (just like tableView viewForIndexPath). So scrolling up or down will call this method.
Beware, you would need to add padding options to first few choices and last few choices just so that it works correctly. This will get you the effect you want. Be warned, Apple might not agree with this method as it doesnt act like what Apple intended picker to do.
Let me know if it works.
If you look at the UIPickerView class reference, you'll see:
selectRow:inComponent:animated:
Selects a row in a specified component
of the picker view.
- (void)selectRow:(NSInteger)row
inComponent:(NSInteger)component
animated:(BOOL)animated
You could call this method when your button is pushed, sending NO for the animated parameter, to instantly select a particular row.

Xcode - HitTesting returns 3 times

I have a UIView subclass where hitTest: withEvent: is overridden. Every time a hit test registers, the view logs its tag.
Ex: Click
Console:
You Touched View: 3
You Touched View: 3
You Touched View: 3
My question: Why does it do it three times? I need it to trigger something other than an NSLog and I'm afraid that it will trigger that three times also. I could easily work around the triple trigger, but I was wondering if there was a better explanation.
I suggest you log the event information as well as the uiview's tag. It could be getting called by multiple events - touchDown, touchUp, etc.

Cocoa Core Data and Tab View - How do I tell when Tab View is finished "loading" so I can tell the view to initialize itself?

I have a simple Core Data app I am building to try to understand Core Data. It has two entities: a weather station, and a collection of observations for a given station.
I created the initial interface for this by putting a tab view on my window, selecting the first tab, and dragging the weather station entity onto that view; then selecting the second tab and dragging the observations entity onto the second tab.
I then created a third tab myself and added a popup at the top. This popup is bound to the StationArrayController, so it populates with all the weather stations I add. This works great.
I then added a table view to display the Observations associated with the selected Station. This also works great. I implemented this with a method that creates a predicate that searches for all observations whose station matches the selected station, and attached the predicate to the ObservationArrayController associated with the Table View on the third tab. (I couldn't figure out how to do this in IB, so I did it programmatically).
The bug is this: If I load a previously saved file with weather stations and observations in it, when I go to the third tab, even though one of the stations is selected (ie, it appears in the popup), all of the observations appear in the tableview, not just the ones associated with that station.
This is happening because I am not calling the method to attach the predicate to the Observation Array Controller until I actually use the popup to change the station manually.
So my problem and question is this (sorry it took so long to get to this point!): How can I detect when the tab view has loaded so I can force the method which attaches the predicate to run and thus have an initial list of Observations which matches the selected Station?
I tried creating a custom View class and subclassing it for the third tab view and putting this code in the awakeFromNib method, but this is too early in the process (the "selected station" is -1 at this point in the loading process).
Any help would be much appreciated. thank you!!
Elisabeth
Ah, I just answered my own question!
I set the delegate of the tabview to MyDocument, and implemented tabView:didSelectTabViewItem: there. I created an IBOutlet in MyDocument pointing to the third tab view, and in this method, checked to see if the third tab was selected, and if so, called the method to attach the predicate to the ObservationArrayController. Works great!

Resources