multiple countdown timers in uitableview - ios

I'm developing a native application clone of Snapchat or Facebook Poke.
I have a few issues related to timers and tap&hold functionality in received messages.
I have a viewcontroller (ViewControllerIncomingMessage) with a tableview which shows received messages and a UILongPressGestureRecognizer that opens a detail view (starts timer and update a countdown label. When the long press gesture ends I dismiss the view and schedule every second the following timer:
- (void)timerFired:(NSTimer *)timer {
[self.tableView reloadData];
}
This actually works but prevents rows from being deleted (because of reloadData of table)
Anyone has already implemented a functionality like that?
Please could you give me any hint about implementing timer update in the best way.

Related

Set UIPicker in motion like a slot machine after a button pressed

I'm very new to objective-c and IOS development. I want to create a very simple slot-machine app. For that I used an UIPicker and filled it with the required data. However I'm having trouble to make it roll after the user clicks a button. I don't have any idea how to implement that kind of movement.
Can anyone give me a direction? I don't have any code to add because everything is displayed like it should, except that method to make the picker actually move which I don't know how to implement at all.
You can accomplish this by loop in animating to a specific row , so create a timer that fires every 1 second inside it increment row / component put this
[picker selectRow:row inComponent:component animated:YES];

iCarousel infinite scroll and index reset

I am working with a carousel in iOS and I am trying to recreate the scrolling banners (featured images) that are present in the iOS app store and iTunes. I have a carousel variable and I would like to get that to scroll exactly like on the apps mentioned above. If you are not familiar with how they scroll, they slide the image and then stop for a period of time.
I have tried carousel.scrollByNumberOfItems(5, duration: 20) which just creates a constant scroll until it is finished. I have played around with different scrolling functions and cannot seem to achieve the desired effect. Again, I am looking for the image to slide, then pause, then slide the next, etc.
My second question is, when the images slide to the end of my images, how can I reset the index if it is passed in as a constant? In other words I am trying to achieve an infinite scrolling effect that will just keep cycling through my images one at a time, similar to the app store.
I am working in swift, but welcome objective c examples as well.
Any help is appreciated!
Thanks!
You can do this pretty easily with an NSTimer to initiate the scrolling.
For example this will scroll every 20 seconds, taking 5 seconds to scroll -
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.scrollTimer=[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:#selector(scrollCarousel) userInfo:nil repeats:YES];
}
-(void) scrollCarousel {
NSInteger newIndex=self.carousel.currentItemIndex+1;
if (newIndex > self.carousel.numberOfItems) {
newIndex=0;
}
[self.carousel scrollToItemAtIndex:newIndex duration:5];
}
as long as your carousel is set to wrap then this will give you what you want.

array's objects loss in storyboards's scene

I make a game that has 2 scenes (first-welcome screen with "start game" button, second - is the game") Game is simple: head-picture is trying to prevent collions with bullets(represented as uiimageviews in NSMutableArray *bullets) with the help of -(void)touchesMoved:withEvent:. If it collides UIAlertView appears to get user's choise: repeat or go to wellcome-scene. If we go to the game-scene first time then everything is OK.
The problem is when we go to the game-scene next time. the property bullets after initiation in viewDidLoad shows its count as 3(as it should), but latter it shows bullets.count == 0;
I don't know how is it possible - I initiate this array in method that calls only in viewDidLoad. And in the first time everything works properly.
P.S. duaring code I don't use propertyName, only self.propertyName.
P.P.S I suggest reason in [UIView commitAnimations] - that's how I make bullets animation.
If I //hide it. evetything is OK. But without animation it looks poor.
Instead of calling the method in viewDidLoad, try calling it in viewDidAppear to set the count to 3 each time the view appears, because it should only be loaded into memory once, but viewDidAppear is called each time the view will show.

How would you program a Continuous Delete Button?

I'm making a calculator app and am supplying my own keypad with UIButtons. I have a delete key and everything works except that the user has to keep pressing the delete key over and over again if they want to delete all.
I was wondering if there is a way to delete everything when the button is held for more than 2 seconds.
The simplest way of implementing this would be attaching a long press gesture recognizer to your [Delete] button.
Xcode lets you attach long press gesture recognizer in the interface builder. Add it to your button, configure the duration of long press, and connect the handler to IBOutlet in the same way that you connect other UI events.
If you would rather do it in code, this answer shows you how.
Use your own timer function to handle this
-(IBAction)buttonHit {
//here start timer that fires for every 2 seconds and handle deletion method in that
}
-(IBAction)buttonReleased {
//Stop timer...
}
In your subclassed UIButton, you might want to watch the "touchesBegan: withEvent:" UIResponder method and if it passes a certain threshold of time, then start deleting like crazy (that is, until the "touchesEnded: withEvent" method gets called).

iOS: Tapping on UITableView does not call didSelectRowAtIndexPath

My app uses a UITableView with a UINavigationController to show a more detailed view when a row of the table is tapped - the basic drill-down routine.
When I tap on a row, it is highlighted, but the delegate methods tableView:willSelectRowAtIndexPath: or tableView:didSelectRowAtIndexPath: are not called (verified using debugger).
Now here's the weird part:
There are some other table views in the app (they don't drill down) and none of them exhibit the issue.
If I tap the row rapidly and repeatedly, after many tries (10 - 20 is normal), tableView:willSelectRowAtIndexPath: and tableView:didSelectRowAtIndexPath: are called and processing continues normally.
The problem occurs only on an (any, actually) iPad running iOS 6. It works fine with iPads running iOS 5, or with any iPhone running any iOS version, 6. It also works with the iPad simulator using iOS 5 or 6.
So it seems that something is receiving the tap before the delegate methods are called. But what?
I not using any UITapGestureRecognizer, so that is not the issue.
I am not using multiple UITableViewControllers for the table, so this is also not the issue.
I was having this issue with an app when running in iOS6. The tableView:didSelectRowAtIndexPath: method was never being triggered, even though it was working before updating to iOS6.
I finally figured it out by looking at the xib and the attribute inspector for the table. In the Table View section I had the Selection option set to No Selection and Show Selection on Touch was not selected.
Changing the Selection option to Single Selection actually got this working for me again and leaving the Show Selection on Touch unselected means that I don't see any flash or change of colour when the row is selected.
I encountered a similar issue. iOS 6 appears to be much more sensitive to the slightest upward movement on a tap on a table view cell. It appears it is registering the slightest movement as a scroll request rather than a cell selection. My table view was set to scrollEnabled = NO because it is a table view with static selection values. The table view appears within a small area of a larger iPad view. If I carefully tap a cell and lift directly up, the cell is selected.
To resolve it, I changed scrollEnabled to YES and made sure the area dedicated to my tableView was larger than the actual area needed to show the table view, thus preventing it from scrolling. Not sure if this is is the cause of the issue you are experiencing, but hope it helps.
I had the same problem. The UITableView was not triggering the didSelectRowAtIndexPath method when running in iOS6, but it was working fine in iOS5.1.
I had also implemented the
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
return NO;
}
and returned NO. In iOS5 it was all working fine, but the minute I switched to iOS6 it would cease to trigger the didSelectRowAtIndexPath. Once I removed that shouldHighlightRow method, everything worked in iOS6 again. Cheers!
The usual reason that didSeletRowAtIndexPath() doesn't get called is having a UITapGestureRecognizer on your viewcontroller with Cancels touches in view set to YES.
The correct and only sensible fix is to set Cancels touches in view to NO. Then your table row selection should work nicely.
Obviously this has some implications in your gesture handlers - you may need to add some code to your gesture handler to stop some touches going on to your views i.e.
- (IBAction)onTapGesture:(UITapGestureRecognizer *)sender {
if (sender.view == someOldViewThatINeedToDealWith) {
sender.cancelsTouchesInView = true;
}
}
I tried all the other answers posted, and although they seemed promising, they didn't solve the problem.
I've since discovered the cause of problem in my case: I was calling [self.tableView reloadData] on a different thread (due to handling an NSNotification event posted from a background worker thread).
I fixed the problem by changing [self.tableView reloadData] to
[self.tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
Hope this helps.
The other suspect could be a Tap Gesture Recognizer set to the view controller's view swallowing all taps like a blackhole. Remove the gesture recognizer will enable did select. I just had the same issue and the tap gesture was the cause.
The resolution is really weird: the UITableViewController registered for all notifications. In the handler for the notifications, the table view data was being reloaded using
[self.tableView reloadData]
According to Apple DTS, when the table reloads data, this causes a notification to be sent to the observer, causing a race condition ...
No explanation for why it would work sometimes or why it would always work on an iPhone. But registering only for a small subset of notifications (i.e. the ones I was really interested in) fixed the problem!
Setting
recognizer.cancelsTouchesInView = NO;
takes care of it if your use case allows simultaneous handling
of touches by [tap] gesture recognizer (kdb dismiss for example)
and the view the recognizer is attached to.
in my case I hade button which received all touch events before tableviewcell

Resources