Skip to main content

Posts

CADisplayLink with NSRunLoopCommonModes not executed for every frame when tracking UIScrollView?

I am trying to execute a small piece of code on every single frame in a regular (non-OpenGL) iPhone app. The goal is to have a frame counter so that I can measure (rather than guess) where the slow points in the app are and fix them to create a better user experience. What I've done so far is register a CADisplayLink for all modes (including tracking): CADisplayLink *displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(frame)] retain]; [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; The code that is executed looks like this (lastDraw is a NSDate* and count an int): - (void) frame { NSDate *newDate = [NSDate date]; if([newDate timeIntervalSinceDate:lastDraw] >= 1) { label.text = [NSString stringWithFormat:@"%d FPS", count]; count = 0; [lastDraw release]; lastDraw = [newDate retain]; } count++; } The idea here is to get an update every one second as to how many frames were drawn in the past s

Can"t show text in the UITableView

I have a view-based app that just does one thing : show a array in a TableView, but it doesn't work and I don't know why. Here's the code. .h @interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{ NSArray *array; IBOutlet UITableView *table; } .m -(void)viewDidLoad{ [super viewDidLoad]; array = [array initWithObjects:@"iPad", @"iTV", nil]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseId

How to implement UINavigationControllerDelegate to call web service for data driven app

In my app, I have 5 navigation controllers. One of the navigation controllers displays 3 view controllers sharing the same data (from a Sqlite database). The only difference is that they present the data in a different way : ViewController 1 = recipes sorted by countries ViewController 2 = recipes sorted by vegetables ViewController 1 = recipes sorted by wines to drink with The Sqlite database is fed with a web-service. As new recipes may be added anytime, I need to refresh the database anytime the application becomes active. And as the application can become active on any of the view controller (depending on the one selected when the app went to background) I have to write the refresh code in the 3 view controller implementation files. I think this method sucks because the web-service is called when the user switch between the navigation controllers. This create frequent and useless traffic and database updates. I would prefer to do the job only one time per applicat

How to get own peerID in a gamekit bluetooth connection?

I know how to get the other players peerID (from the didConnectPeer event or when i receive data) but how can i get the peerid of the iphone itself after a connection has been made? EDIT Seems to be wrong though. The peerID from didpeerPickerController:didConnectPeer:toSession: seems to be the peer you connected TO. I did this check: -(void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session { CCLOG(@"I am %@", peerID); [picker dismiss]; picker.delegate = nil; picker autorelease]; } -(void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession*)session context:(void *)context { CCLOG(@"Received from %@", peer); } 2012-02-05 21:06:18.093 x[2546:707] I am 77606856 2012-02-05 21:06:19.154 x[2546:707] Received from 77606856 And i would get the same id on both printouts when sending something from the other iphonedevice. Did i maybe missunders

Unclear on how to properly remove a UIViewController from another UIViewController

thank you for your time, (As a side note, this question pertains mostly to iOS 4.2.3, I am aware some of these issues could be resolved with moving the code base to iOS 5, however we would like to release this app for phones running iOS 4 as well.) I have a "MasterViewController" that is in charge of calling and dismising other UIVIewControllers. First we trigger a new one: In MasterViewController.m -(IBAction)triggerPrime:(id)sender { [self clearHomeScreen]; NSUInteger randomNumber = arc4random() % 2; if (randomNumber == 0) { self.flashTextViewIsDisplayed = NO; ThinkOfViewController *thinkVC = [[ThinkOfViewController alloc] initWithNibName:@"ThinkOfViewController" bundle:nil]; self.thinkOfViewController = thinkVC; [thinkVC release]; self.picturePrimeViewIsDisplayed = YES; [self.view addSubview:self.thinkOfViewController.view]; } else if (randomNumber == 1) { self.picturePrime

Resigning keyboard on touch

I've found some code that helps me resign the keyboard when a user touches the screen off of the UITextView element. Here's how it looks: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches] anyObject]; if([self.speechBubble.speechText isFirstResponder] && [touch view] != self.speechBubble.speechText){ [self.speechBubble.speechText resignFirstResponder]; } [super touchesBegan:touches withEvent:event]; } This works perfectly so far, and will remove the keyboard if a user touches anywhere outside of the text view. However, it only works for the particular object that I'm running it for, so if I have two speechBubbles, it won't work. How can I change this so that ANY speechBubble will have the same effect? (I could move this code from my ViewController to my SpeechBubble class, but I'd have a little issue with how to use [touch view] to get touches outside of the speechBubble's view. ) Thanks