Search Results

Search found 447 results on 18 pages for 'uibutton'.

Page 18/18 | < Previous Page | 14 15 16 17 18 

  • Grouped UITableView Footer Sometimes Hidden On Quick Scroll

    - by jdandrea
    OK, this one is a puzzler. There is one similar post but it's not similar enough to count, so I'm posting this one. :) I've got a grouped UITableView with a header and footer. The footer includes two UIButton views, side-by-side. Nothing major. Now … there is a toggle button in a UIToolbar at the bottom for more/less info in this table view. So I build my index paths to delete/insert with fade row animation, all the usual ingredients, sandwiched between beginUpdates and endUpdates calls on the UITableView … and this works fine! In also happens that my footer can sometimes be pushed off past the bottom of the display. Here's where it gets weird. If I drag my finger up the display, scrolling the view upward, I should see that footer eventually, right? Well … most of the time I do. BUT, if I flick my finger up, for a faster scroll, the footer is missing. Even if you try to tap in that area - no response. However, if I scroll back down again, just to hide that footer (or rather hide the area where the footer would normally be), and then scroll back up, it's there once again! This only happens when inserting rows. If I delete rows, the footer stays put … unless of course it was already hidden and I didn't perform the aforementioned incantation to get it back. :) I am trying to trace through this, but to no avail. I suppose tracing through scroll operations is a bit of a crazy proposition! Perhaps some creative logging … suggestions, anyone? Or is this a known issue in 3.1 where row insert/deletes are concerned? (I don't recall seeing it until 3.1.)

    Read the article

  • continueTrackingWithTouch: withEvent: not being called continuously.

    - by Steven Noyes
    I have a very simply subclass of UIButton that will fire off a custom event when the button has been held for 2 seconds. To accomplish this, I overrode: // // Mouse tracking // - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { [super beginTrackingWithTouch:touch withEvent:event]; [self setTimeButtonPressed:[NSDate date]]; return (YES); } - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { [super continueTrackingWithTouch:touch withEvent:event]; if ([[self timeButtonPressed] timeIntervalSinceNow] > 2.0) { // // disable the button. This will eventually fire the event // but this is just stubbed to act as a break point area. // [self setEnabled:NO]; [self setSelected:NO]; } return (YES); } My problem is (this is in the simulator, can't do on device work quite yet) "continueTrackingWithTouch: withEvent:" is not being called unless the mouse is actually moved. It does not take much motion, but it does take some motion. By returning "YES" in both of these, I should be setup to receive continuous events. Is this an oddity of the simulator or am I doing something wrong? NOTE: userInteractionEnabled is set to YES. NOTE2: I could setup a timer in beginTrackingWithTouch: withEvent: but that seems like more effort for something that should be simple.

    Read the article

  • About updating a View using in iPhone using Objective C.

    - by Tattat
    I have a scene, called testScene, it works like this: @interface testScene : myScene { IBOutlet UIView *subview; IBOutlet UIView *drawingCanvasView; IBOutlet UIButton *update; } - (void)updateDrawingCanvas: (id) sender; and when the user click the button, update, it will run the updateDrawingCanvas method. So, I have a drawingCanvasView, which gave a drawingCanvas.h, and .m, it like this: #import <UIKit/UIKit.h> @interface DrawingCanvasView : UIView { CGImageRef image; } -(void)setNeedsDisplayInRect:(CGContextRef)context; @end In the DrawingCanvasView, I have a drawRect method like this: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGContextMoveToPoint(context, 0.0f, 0.0f); CGContextAddLineToPoint(context, 100.0f, 100.0f); CGContextStrokePath(context); And I want the user click the button, and execute this, so I added a new method called setNeedsDisplayInRect: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context, 2.0); CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor); CGContextMoveToPoint(context, 0.0f, 0.0f); CGContextAddLineToPoint(context, 200.0f, 200.0f); CGContextStrokePath(context); But I can't called that in my updateDrawingCanvas method, it work like this: - (void)updateDrawingCanvas: (id) sender{ NSLog(@"loaded"); [DrawingCanvasView setNeedsDisplayInRect:UIGraphicsGetCurrentContext()]; } It my logic / concept right? or something I did wrong, thx.

    Read the article

  • commitAnimations is not resizing my UIImageView subview

    - by AaronG
    I have created a UIView as a subview and to that subview I have added a UIImageView as a subview. UIView *viewCreated; UIButton *buttonCreated; UIImageView *imageViewCreated; CGRect myFrame = CGRectMake(0, 0, 1024, 1024); viewCreated = [[UIView alloc] initWithFrame:myFrame]; [viewCreated setTag:intTag]; viewCreated.backgroundColor = [UIColor redColor]; [self.view addSubview:viewCreated]; [self randomize]; UIImage *d1Image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", randomNumber]]; imageViewCreated = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f,0.0f,1024.0f, 1024.0f)]; [imageViewCreated setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", randomNumber]]]; [viewCreated addSubview:imageViewCreated]; //[imageViewCreated release]; return [viewCreated autorelease]; But when this code executes only the first subview is animated and resized. The UiimageView moves 200 pixels to the left but does not get resized. NSLog(@"sender tag %i",[sender tag]); UIView *currentView = [self.view viewWithTag:[sender tag]]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.5]; currentView.frame = CGRectMake(-200, 0,40, 102); [UIView commitAnimations]; I am pretty sure am I not creating the subviews correctly programmatically, because when I do it in Interface Builder it works as expected. Do I have to do something specific to actually attach the behavior of the second subview to the first subview?

    Read the article

  • The rightCalloutAccessory button is not shown

    - by Luca
    I try to manage annotations, and to display an info button on the right of the view when a PIN get selected, my relevant code is this: - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenPin"]; if ([annotation isKindOfClass:[ManageAnnotations class]]) { static NSString* identifier = @"ManageAnnotations"; MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; if (newAnnotation==nil) { newAnnotation=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; }else { newAnnotation.annotation=annotation; } newAnnotation.pinColor = MKPinAnnotationColorGreen; newAnnotation.animatesDrop = YES; newAnnotation.canShowCallout = YES; newAnnotation.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeInfoLight]; return newAnnotation; }else { newAnnotation.pinColor = MKPinAnnotationColorGreen; newAnnotation.animatesDrop = YES; newAnnotation.canShowCallout = YES; return newAnnotation; } ManageAnnotations.m : @implementation ManageAnnotations @synthesize pinColor; @synthesize storeName=_storeName; @synthesize storeAdress=_storeAdress; @synthesize coordinate=_coordinate; -(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate{ if((self=[super init])){ _storeName=[storeName copy]; _storeAdress=[storeAdress copy]; _coordinate=coordinate; } return self; } -(NSString*)title{ return _storeName; } -(NSString*)subtitle{ return _storeAdress; } ManageAnnotations.h @interface ManageAnnotations : NSObject<MKAnnotation>{ NSString *_storeName; NSString *_storeAdress; CLLocationCoordinate2D _coordinate; } // @property(nonatomic,assign)MKPinAnnotationColor pinColor; @property(nonatomic, readonly, copy)NSString *storeName; @property(nonatomic, readonly, copy)NSString *storeAdress; @property(nonatomic,readonly)CLLocationCoordinate2D coordinate; // -(id)initWithTitle:(NSString*)storeName adress:(NSString*)storeAdress coordinate:(CLLocationCoordinate2D)coordinate; // The PINS are shown correctly on the Map, but without the info button on the right of the view. Am i missing something?

    Read the article

  • Nested Views-button aint clicking

    - by Deepika
    i have a view which has a datepicker and a button added to it. There is another view which adds the above view as subview. But the events like touchesBegan and button's action are not being clicked on the subview. Please help The code of the parent view is: iTagDatePicker *dt=[[iTagDatePicker alloc] initWithFrame:CGRectMake(0.0, 180.0, 320.0, 240.0)]; //dt.userInteractionEnabled=YES; //[dt becomeFirstResponder]; dt.backgroundColor=[UIColor clearColor]; [UIView beginAnimations:@"animation" context:nil]; [UIView setAnimationDuration:1.0]; CGPoint cntr; cntr.x=160.0; cntr.y=420.0; dt.center=cntr; [self.view addSubview:dt]; self.view.userInteractionEnabled=YES; CGPoint cntr1; cntr1.x=160.0; cntr1.y=158.0; dt.center=cntr1; [UIView commitAnimations]; [dt release]; and the code for the sub class is: - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { dtPicker=[[UIDatePicker alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, 320.0, 216.0)]; dtPicker.datePickerMode=UIDatePickerModeDate; dtPicker.date=[NSDate date]; [self addSubview:dtPicker]; btn=[[UIButton buttonWithType:UIButtonTypeDetailDisclosure]retain]; btn.frame=CGRectMake(110.0, 400.0, 100.0, 20.0); [btn setTitle:@"Done" forState:UIControlStateNormal]; btn.userInteractionEnabled=YES; [btn becomeFirstResponder]; [btn addTarget:self action:@selector(SelectedVal:) forControlEvents:UIControlEventTouchDown]; [self addSubview:btn]; } return self; } The button is not working

    Read the article

  • How to delete a cell in UITableView by using custom button in cell ?

    - by srikanth rongali
    I have UITableView. I customized the cell height (increased). I have 4 labels(UILabel) and 1 image(UIImage) and 3 buttons (UIButton). one of the button is delete button. By touching the cell or button(play button) on the image a video is loaded and played. I need to delete the cell by touching delete button. If I touched the delete button the corresponding video is deleted from library . But, how to delete the cell and all remaining data in it ? I am not able to delete the cells or the data in the cells. How to do it ? I used these. But the control is not entering in to second method committedEditingStyle: - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { } } Thank you. The following image shows the delete button of my program.

    Read the article

  • Sharing same properties of ViewController for iPhone Stroryboard and iPad Story Board

    - by Ruhul Amin
    I'm developing a universal application. in the first view, I have the login screen for the user. In iPhone storyBoard, I have added 2 text field and one button( login check). I have added properties in ViewController.h file by dragging those objects(Ctrl key + Dragg) to .h file. I have added code for login check and it is working fine for iPhone. This is the code in ViewController.h @property (strong, nonatomic) IBOutlet UITextField *txtUserId; @property (strong, nonatomic) IBOutlet UITextField *txtUserPwd; @property (strong, nonatomic) IBOutlet UIButton *btnLogin; In the iPad storyBoard, I have added 2 text field( userid and password) and i button for login. So now, I want to bind those objects with the veriable which I declared already in ViewController.h file in case of iPhone. My questions: 1. What is the right way to bind properties for both storyboard? 2. Am I on the right direction or should I think in a different way to do it? I am new with iPhone development. Please help. Thanks. --Amin

    Read the article

  • Can't add or remove object from NSMutableSet

    - by Dan Ray
    Check it: - (IBAction)toggleFavorite { DataManager *data = [DataManager sharedDataManager]; NSMutableSet *favorites = data.favorites; if (thisEvent.isFavorite == YES) { NSLog(@"Toggling off"); thisEvent.isFavorite = NO; [favorites removeObject:thisEvent.guid]; [favoriteIcon setImage:[UIImage imageNamed:@"notFavorite.png"] forState:UIControlStateNormal]; } else { NSLog(@"Toggling on, adding %@", thisEvent.guid); thisEvent.isFavorite = YES; [favorites addObject:thisEvent.guid]; [favoriteIcon setImage:[UIImage imageNamed:@"isFavorite.png"] forState:UIControlStateNormal]; } NSLog(@"favorites array now contains %d members", [favorites count]); } This is fired from a custom UIButton. The UI part works great--toggles the image used for the button, and I can see from other stuff that the thisEvent.isFavorite BOOL is toggling happily. I can also see in the debugger that I'm getting my DataManager singleton. But here's my NSLog: 2010-05-13 08:24:32.946 MyApp[924:207] Toggling on, adding 05db685f65e2 2010-05-13 08:24:32.947 MyApp[924:207] favorites array now contains 0 members 2010-05-13 08:24:33.666 MyApp[924:207] Toggling off 2010-05-13 08:24:33.666 MyApp[924:207] favorites array now contains 0 members 2010-05-13 08:24:34.060 MyApp[924:207] Toggling on, adding 05db685f65e2 2010-05-13 08:24:34.061 MyApp[924:207] favorites array now contains 0 members 2010-05-13 08:24:34.296 MyApp[924:207] Toggling off 2010-05-13 08:24:34.297 MyApp[924:207] favorites array now contains 0 members Worst part is, this USED to work, and I don't know what I did to break it.

    Read the article

  • UIViewController maintains state after being nilled

    - by Eric
    In my app, I made a BookViewController class that displays and animates the pages of a book and a MainMenuViewController class that displays a set of books the user can read. In the latter class, when the user taps on one of the books, a function is called that should create a completely new instance of BookViewController, but for some reason the instance maintains its state (i.e. it resumes from the page the user left off). How can this be if I set it to nil? What am I missing here? (Note that I'm using ARC). MainMenuViewController.m @interface MainMenuViewController () @property (strong) BookViewController *bookViewController; @end @implementation MainMenuViewController @synthesize bookViewController; -(void)bookTapped:(UIButton *)sender{ NSString *bookTitle; if(sender == book1button) bookTitle = @"book1"; else if(sender == book2button) bookTitle = @"book2"; bookViewController = nil; bookViewController = [[BookViewController alloc] initWithBookTitle:bookTitle]; [self presentViewController:bookViewController animated:YES completion:nil]; } BookViewController.h @interface BookViewController : UIViewController -(id)initWithBookTitle:(NSString *)bookTitle; @end BookViewController.m @implementation BookViewController -(id)initWithBookTitle:(NSString *)theBookTitle{ self = [super init]; if(self){ bookTitle = [NSString stringWithFormat:@"%@", theBookTitle]; [self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; NSLog(@"init a BookViewController with bookTitle: %@", bookTitle); } return self; } Every time a book is tapped, bookTapped: is called, and thee console always prints: 2012-08-31 16:29:51.750 AppName[25713:c07] init a BookViewController with bookTitle: book1 So if a new instance of BookViewController is being created, how come it seems to be returning the old one?

    Read the article

  • when i set property(retain), one "self" = one "retain"?

    - by Walter
    although I'm about to finish my first app, I'm still confused about the very basic memory management..I've read through many posts here and apple document, but I'm still puzzled.. For example..I'm currently doing things like this to add a label programmatically: @property (retain, nonatomic) UILabel *showTime; @sythesize showTime; showTime = [[UILabel alloc] initWithFrame:CGRectMake(45, 4, 200, 36)]; [self.showTime setText:[NSString stringWithFormat:@"%d", time]]; [self.showTime setFont:[UIFont fontWithName:@"HelveticaRoundedLT-Bold" size:23]]; [self.showTime setTextColor:numColor]; self.showTime.backgroundColor = [UIColor clearColor]; [self addSubview:self.showTime]; [showTime release]; this is my current practice, for UILabel, UIButton, UIImageView, etc... [Alloc init] it without self., coz I know this will retain twice.. but after the allocation, I put back the "self." to set the attributes.. My gut feel tells me I am doing wrong, but it works superficially and I found no memory leak in analyze and instruments.. can anyone give my advice? when I use "self." to set text and set background color, does it retain one automatically? THX so much!

    Read the article

  • remove 2 subviews in one go.

    - by Pavan
    hi, I am trying to remove two viewcontrollers (that have been added on top of each other) with one method. I have made the views in interfacebuilder. they all have their own .h and .m files to go with it. Scenario I am in: I have a main menu which has the view2 header file imported. In a method I add the second view on top of the superview like so view2ViewController * view2 = [[view2ViewController alloc] initWithNibName:@"view2ViewController" bundle:nil]; [self.view addSubview:view2.view]; then in view 2 I have added the view 3 header file so i can add view 3 as a subview ontop of view2. i have another method which is connected again to interface builder to a UIButton so upon button press a method gets called in view2 which adds view 3 on top in exactly the same way like so: view3ViewController * view3 = [[view3ViewController alloc] initWithNibName:@"view3ViewController" bundle:nil]; [self.view addSubview:view3.view]; What im trying to solve: I have a button in view 3 which should remove view 3.... and then it should also remove view 2 aswell so the main screen is visible. How can this be achieved? What I have so far: [self.view removeFromSuperview]; This however only removes View 3... but leaves view 2 in place. What needs to be modified so that i can remove view 2 as well?? Any help is appreciated.

    Read the article

  • How to make sure an action completes before you continue

    - by HurkNburkS
    I am trying to close a UIView thats in one method from another method by calling it, The UIView closes fine but not untill after all of the processes are finished in the current method. I would like to know if there is a way to force the first thing to happen first (i.e. close UIviews) then continue the current method? This is what my method looks like - (void)selectDeselectAllPressed:(UIButton*)button { int id = button.tag; [SVProgressHUD showWithStatus:@"Updating" maskType:SVProgressHUDMaskTypeGradient]; [self displaySelected]; // removes current view so you can load hud will not be behind it if (id == 1) { [self selectAllD]; } else if (id == 2) { [self deselectAllD]; } else if (id == 3) { [self selectAllI]; } else if (id == 4) { [self deselectAllI]; } } as you can see what happens is this method is called when a button is pressed, I would like for the displaySelected method to do what it needs to do before any of the other methods are called? Currently what happes when i debug this is displaySelected method is called the thread walks through that then continues to the if statment then after the method in the if statment has finished then displaySelected changes are made... its so weird. any help would be greatly appreciated.

    Read the article

  • AVAudioRecorder Memory Leak

    - by Eric Ranschau
    I'm hoping someone out there can back me up on this... I've been working on an application that allows the end user to record a small audio file for later playback and am in the process of testing for memory leaks. I continue to very consistently run into a memory leak when the AVAudioRecorder's "stop" method attempts to close the audio file to which it's been recording. This really seems to be a leak in the framework itself, but if I'm being a bonehead you can tell me. To illustrate, I've worked up a stripped down test app that does nothing but start/stop a recording w/ the press of a button. For the sake of simplicty, everything happens in app. delegate as follows: @synthesize audioRecorder, button; @synthesize window; - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // create compplete path to database NSString *tempPath = NSTemporaryDirectory(); NSString *audioFilePath = [tempPath stringByAppendingString:@"/customStatement.caf"]; // define audio file url NSURL *audioFileURL = [[NSURL alloc] initFileURLWithPath:audioFilePath]; // define audio recorder settings NSDictionary *settings = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey, [NSNumber numberWithInt:1], AVNumberOfChannelsKey, [NSNumber numberWithInt:AVAudioQualityLow], AVSampleRateConverterAudioQualityKey, [NSNumber numberWithFloat:44100], AVSampleRateKey, [NSNumber numberWithInt:8], AVLinearPCMBitDepthKey, nil ]; // define audio recorder audioRecorder = [[AVAudioRecorder alloc] initWithURL:audioFileURL settings:settings error:nil]; [audioRecorder setDelegate:self]; [audioRecorder setMeteringEnabled:YES]; [audioRecorder prepareToRecord]; // define record button button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(handleTouch_recordButton) forControlEvents:UIControlEventTouchUpInside]; [button setFrame:CGRectMake(110.0, 217.5, 100.0, 45.0)]; [button setTitle:@"Record" forState:UIControlStateNormal]; [button setTitle:@"Stop" forState:UIControlStateSelected]; // configure the main view controller UIViewController *viewController = [[UIViewController alloc] init]; [viewController.view addSubview:button]; // add controllers to window [window addSubview:viewController.view]; [window makeKeyAndVisible]; // release [audioFileURL release]; [settings release]; [viewController release]; return YES; } - (void) handleTouch_recordButton { if ( ![button isSelected] ) { [button setSelected:YES]; [audioRecorder record]; } else { [button setSelected:NO]; [audioRecorder stop]; } } - (void) dealloc { [audioRecorder release]; [button release]; [window release]; [super dealloc]; } The stack trace from Instruments that shows pretty clearly that the "closeFile" method in the AVFoundation code is leaking...something. You can see a screen shot of the Instruments session here: Developer Forums: AVAudioRecorder Memory Leak Any thoughts would be greatly appreciated!

    Read the article

  • Looking for Reachability (2.0) Use Case Validation

    - by user350243
    There is so much info out there on using Apple's Reachability example, and so much is conflicting. I'm trying to find out of I'm using it (Reachability 2.0) correctly below. My App use case is this: If an internet connection is available through any means (wifi, LAN, Edge, 3G, etc.) a UIButton ("See More") is visible on various views. If no connection, the button is not visible. The "See More" part is NOT critical in any way to the app, it's just an add-on feature. "See More" could be visible or not anytime during the application lifecycle as connection is established or lost. Here's how I did it - Is this correct and/or is there a better way? Any help is Greatly Appreciated! lq // AppDelegate.h #import "RootViewController.h" @class Reachability; @interface AppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; UINavigationController *navigationController; RootViewController *rootViewController; Reachability* hostReach; // NOT USED: Reachability* internetReach; // NOT USED: Reachability* wifiReach; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; @property (nonatomic, retain) IBOutlet RootViewController *rootViewController; @end // AppDelegate.m #import "AppDelegate.h" #import "Reachability.h" #define kHostName @"www.somewebsite.com" @implementation AppDelegate @synthesize window; @synthesize navigationController; @synthesize rootViewController; - (void) updateInterfaceWithReachability: (Reachability*) curReach { if(curReach == hostReach) { NetworkStatus netStatus = [curReach currentReachabilityStatus]; BOOL connectionRequired = [curReach connectionRequired]; // Set a Reachability BOOL value flag in rootViewController // to be referenced when opening various views if ((netStatus != ReachableViaWiFi) && (netStatus != ReachableViaWWAN)) { rootViewController.bConnection = (BOOL *)0; } else { rootViewController.bConnection = (BOOL *)1; } } } - (void) reachabilityChanged: (NSNotification* )note { Reachability* curReach = [note object]; NSParameterAssert([curReach isKindOfClass: [Reachability class]]); [self updateInterfaceWithReachability: curReach]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { // NOTE: #DEFINE in Reachability.h: // #define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification" [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil]; hostReach = [[Reachability reachabilityWithHostName: kHostName] retain]; [hostReach startNotifer]; [self updateInterfaceWithReachability: hostReach]; [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; } - (void)dealloc { [navigationController release]; [rootViewController release]; [window release]; [super dealloc]; } @end

    Read the article

  • Setting shadowColor with property syntax gives compiler error: Expected identifier before '[' token.

    - by sam
    I have an iPad app in which I'm setting the shadow color of a UILabel in a UIView's initWithFrame: method. When I use the following syntax: m_label.shadowColor = [UIColor colorWithWhite:1.0 alpha:0.5]; I get this compiler error: Expected identifier before '[' token However, when I use the following syntax: [m_label setShadowColor:[UIColor colorWithWhite:1.0 alpha:0.5]]; It compiles without complaint. Using property syntax for other properties of the UILabel is working fine (shadowOffset, autoresizingMask, backgroundColor, font, textColor, etc.). Incidentally, I get the same error message when the statement is simply this: m_label.shadowColor; Whereas this, for example, gives no error: m_label.shadowOffset; FWIW, the entire method looks like this: #define shadowColor [UIColor colorWithWhite:1.00 alpha:0.5] #define selectedColor [UIColor colorWithWhite:0.25 alpha:1.0] #define unselectedColor [UIColor colorWithWhite:0.45 alpha:1.0] #define CLOSEBUTTON_WIDTH 26.0 #define CLOSEBUTTON_HEIGHT 26.0 - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { m_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.frame.size.width, self.frame.size.height)]; m_imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; m_imageView.backgroundColor = [UIColor clearColor]; m_imageView.image = [[UIImage imageNamed:@"tab.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0]; m_imageView.highlightedImage = [[UIImage imageNamed:@"tabSelected.png"] stretchableImageWithLeftCapWidth:8.0 topCapHeight:0.0]; m_label = [[UILabel alloc] initWithFrame:CGRectZero]; m_label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; m_label.backgroundColor = [UIColor clearColor]; m_label.font = [UIFont boldSystemFontOfSize:12.0]; m_label.textColor = unselectedColor; m_label.shadowOffset = CGSizeMake(0.0, 1.0); m_label.shadowColor = shadowColor; // Expected identifier before '[' token [m_label setShadowColor:shadowColor]; m_closeButton = [[UIButton alloc] initWithFrame:CGRectMake(9.0, 1.0, CLOSEBUTTON_WIDTH, CLOSEBUTTON_HEIGHT)]; [m_closeButton setBackgroundImage:[UIImage imageNamed:@"tabClose.png"] forState:UIControlStateNormal]; [m_closeButton addTarget:self action:@selector(closeTab) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:m_imageView]; [self addSubview:m_label]; [self addSubview:m_closeButton]; self.backgroundColor = [UIColor clearColor]; } return self; } Any ideas?

    Read the article

  • Line Graph CGPoints from NSMutableArray

    - by Mattog1456
    I have been trying to adapt the code from the accelerometer example such that when the user depresses a uibutton a point is added to a line graph. Working on the converting two floats, which are the result of calculate as below into a CGPoint and converting the CGPoint into an NSValue and then adding this to a NSMutableArray with the following -(IBAction)calculate:(id)sender { self.points = [NSMutableArray array]; CGPoint pt = CGPointMake(d, c); [self.points addObject:[NSValue valueWithCGPoint:pt]]; NSLog(@"%@", NSStringFromCGPoint(pt)); NSLog(@"%@", [NSString stringWithFormat:@"%d points", self.points.count ]); } But for some reason I am only getting one object stored in the array, it seems everytime push the calculate button the object pt gets overwritten, on the plus side it has the correct x,y coords. Any ideas on this one? UPDATE Removed self.points = [NSMutableArray array]; and placed it in view did load, also set the first points to 0,0. so that is working ok. Now the next problem is that I have a Graph subclass where the CG Drawing is taking place. I am trying to figure out a simple way to be able to access the above NSMutableArray which is in a ViewController class from the graph class. Am so close to the end but am really stuck, any help would be great. Still trying to draw a line graph on a UIView which is on a UIScrollview. The draw rect method is in the UIView Subclass and everything is working there, I have gridlines and labels on the axis and I can draw manually onto it. But the problem I have is that I cannot read the NSMutableArray of the CGPoints, which are the x and y coords. The ViewController performs a calculation and the results are written to the NSMutable array and this is all working fine as well, I can see the CGpoints and their values being written with NSLogs in the ViewController. I have tried various ways to set the NSMutableArray up as a global but to no avail, everything runs but while I can see the points being written in the ViewController they are just not visible to the UIView Subclass. I have also tried to use the addObserver and observeValueForKeyPath methods and once again while everything runs the subclass cannot see the array. Any ideas, suggestions, tips or thoughts would be great

    Read the article

  • random generator to obtain data from array not displaying

    - by Yang Jie Domodomo
    I know theres a better solution using arc4random (it's on my to-try-out-function list), but I wanted to try out using the rand() and stand(time(NULL)) function first. I've created a NSMutableArray and chuck it with 5 data. Testing out how many number it has was fine. But when I tried to use the button function to load the object it return me with object <sampleData: 0x9a2f0e0> - (IBAction)generateNumber:(id)sender { srand(time(NULL)); NSInteger number =rand()% ds.count ; label.text = [NSString stringWithFormat:@"object %@", [ds objectAtIndex:number] ]; NSLog(@"%@",label.text); } While I feel the main cause is the method itself, I've paste the rest of the code below just incase i made any error somewhere. ViewController.h #import <UIKit/UIKit.h> #import "sampleData.h" #import "sampleDataDAO.h" @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UILabel *label; @property (weak, nonatomic) IBOutlet UIButton *onHitMePressed; - (IBAction)generateNumber:(id)sender; @property(nonatomic, strong) sampleDataDAO *daoDS; @property(nonatomic, strong) NSMutableArray *ds; @end ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize label; @synthesize onHitMePressed; @synthesize daoDS,ds; - (void)viewDidLoad { [super viewDidLoad]; daoDS = [[sampleDataDAO alloc] init]; self.ds = daoDS.PopulateDataSource; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [self setLabel:nil]; [self setOnHitMePressed:nil]; [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } - (IBAction)generateNumber:(id)sender { srand(time(NULL)); NSInteger number =rand()% ds.count ; label.text = [NSString stringWithFormat:@"object %@", [ds objectAtIndex:number] ]; NSLog(@"%@",label.text); } @end sampleData.h #import <Foundation/Foundation.h> @interface sampleData : NSObject @property (strong,nonatomic) NSString * object; @end sampleData.m #import "sampleData.h" @implementation sampleData @synthesize object; @end sampleDataDAO.h #import <Foundation/Foundation.h> #import "sampleData.h" @interface sampleDataDAO : NSObject @property(strong,nonatomic)NSMutableArray*someDataArray; -(NSMutableArray *)PopulateDataSource; @end sampleDataDAO.m #import "sampleDataDAO.h" @implementation sampleDataDAO @synthesize someDataArray; -(NSMutableArray *)PopulateDataSource { someDataArray = [[NSMutableArray alloc]init]; sampleData * myData = [[sampleData alloc]init]; myData.object= @"object 1"; [someDataArray addObject:myData]; myData=nil; myData = [[sampleData alloc] init]; myData.object= @"object 2"; [someDataArray addObject:myData]; myData=nil; myData = [[sampleData alloc] init]; myData.object= @"object 3"; [someDataArray addObject:myData]; myData=nil; myData = [[sampleData alloc] init]; myData.object= @"object 4"; [someDataArray addObject:myData]; myData=nil; myData = [[sampleData alloc] init]; myData.object= @"object 5"; [someDataArray addObject:myData]; myData=nil; return someDataArray; } @end

    Read the article

  • iPhone NSCalendar - Incorrect Calendar Drawn for users outside US

    - by xoail
    After trying to work on someone else's code, and so many different iterations, I am unable to understand what am I doing wrong with dates on a calendar month view. I am trying to present a calendar in month view fashion like calendar.app but unfortunately some users in countries like Australia, UK are reporting incorrect alignment of Days to Dates. For instance in Australia it displays 17th March as Friday. Any help is highly appreciated! Here is the code sample I am using: -(void)setCalendar { NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *comps = [gregorian components:units fromDate:[NSDate date]]; self.currentDate = [gregorian dateFromComponents:comps]; NSInteger weekdayInteger=[comps weekday]; currentMonth=[comps month]; currentYear=[comps year]; NSString *dateString=[[NSString stringWithFormat:@"%@",currentDate] substringToIndex:10]; NSArray *array= [dateString componentsSeparatedByString:@"-"]; NSInteger currentDay=[[array objectAtIndex:2] intValue]; currentMonthConstant=currentMonth; currentYearConstant=currentYear; currentDayConstant=currentDay; currentConstantDate=[NSString stringWithFormat:@"%d/%d/%d",currentDayConstant,currentMonthConstant,currentYearConstant]; currentFirstDay=((8+weekdayInteger-(currentDay%7))%7); if(currentFirstDay==0) currentFirstDay=7; [gregorian release]; } And this is how im populating the calendar: -(void)fillCalender:(NSInteger)month weekStarts:(NSInteger)weekday year:(NSInteger)year { currentMonth=month; currentYear=year; currentFirstDay=weekday; UIButton *temp; NSInteger numberOfDays=[self getNumberofDays:month YearVlue:year]; currentLastDay=(currentFirstDay+numberOfDays-1)%7; if(currentLastDay==0) currentLastDay=7; NSString *monthName=[self getMonth:month]; NSInteger grid=(weekday-1); monthLabel.text=[NSString stringWithFormat:@"%@ %d",monthName,year]; for(int i=1;i<=numberOfDays;i++) { if([frontView isEqualToString:@"view1"]) temp=[arr_View2Buttons objectAtIndex:grid]; else temp= [arr_View1Buttons objectAtIndex:grid]; [temp setBackgroundImage:nil forState:UIControlStateNormal]; [temp setUserInteractionEnabled:TRUE]; UILabel *aLbl = (UILabel *)[temp viewWithTag:123]; [aLbl setText:[NSString stringWithFormat:@"%d",i]]; // check for today if(currentDayConstant == i && currentMonthConstant == currentMonth && currentYearConstant == currentYear) { [aLbl setTextColor:[UIColor blueColor]]; } else { [aLbl setTextColor:[UIColor colorWithRed:69/255.0 green:2/255.0 blue:71/255.0 alpha:1.0]]; } [temp setTag:i]; grid++; if(grid==35) grid=0; } } And finally viewdidload: - (void)viewDidLoad { [super viewDidLoad]; [self setCalendar]; // set views [self.view1 setFrame:CGRectMake(0,45,320,232)]; [self.view2 setFrame:CGRectMake(0,277,320,232)]; [self.view addSubview:self.view1]; [self.view addSubview:self.view2]; frontView = @"view2"; [self fillCalender:currentMonth weekStarts:currentFirstDay year:currentYear]; frontView = @"view1"; }

    Read the article

  • populate uipicker view with results from core data DB using an NSArray

    - by Chris
    I am trying to populate a UIPickerView with the results of a NSFetchRequest. The results of the NSFetchRequest are then stored in an NSArray. I am using Core Data to interact with the SQLite DB. I have a simple class file that contains a UIPickerView that is associated with a storyboard scene in my project. The header file for the class looks like the following, ViewControllerUsers.h #import <UIKit/UIKit.h> #import "AppDelegate.h" @interface ViewControllerUsers : UIViewController <NSFetchedResultsControllerDelegate, UIPickerViewDelegate, UIPickerViewDataSource> { NSArray *dictionaries; } @property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController; // Core Data @property (strong, nonatomic) NSManagedObjectContext *managedObjectContext; @property (nonatomic, strong) NSArray *users; @property (strong, nonatomic) IBOutlet UIPickerView *uiPickerViewUsers; @property (weak, nonatomic) IBOutlet UIBarButtonItem *btnDone; @property (weak, nonatomic) IBOutlet UIButton *btnChangePin; // added for testing purposes @property (nonatomic, strong) NSArray *usernames; - (IBAction)dismissScene:(id)sender; - (IBAction)changePin:(id)sender; @end The implementation file looks like the following, ViewControllerUsers.m #import "ViewControllerUsers.h" @interface ViewControllerUsers () @end @implementation ViewControllerUsers // Core Data @synthesize managedObjectContext = _managedObjectContext; @synthesize uiPickerViewUsers = _uiPickerViewUsers; @synthesize usernames = _usernames; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // Core Data if (_managedObjectContext == nil) { _managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; NSLog(@"After _managedObjectContext: %@", _managedObjectContext); } NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Account"]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Account" inManagedObjectContext:_managedObjectContext]; request.resultType = NSDictionaryResultType; request.propertiesToFetch = [NSArray arrayWithObject:[[entity propertiesByName] objectForKey:@"username"]]; request.returnsDistinctResults = YES; _usernames = [_managedObjectContext executeFetchRequest:request error:nil]; NSLog (@"names: %@",_usernames); } -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { //One column return 1; } -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { //set number of rows return _usernames.count; } -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //set item per row return [_usernames objectAtIndex:row]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidUnload { [self setBtnDone:nil]; [self setUiPickerViewUsers:nil]; [self setBtnChangePin:nil]; [super viewDidUnload]; } - (IBAction)dismissScene:(id)sender { [self dismissModalViewControllerAnimated:YES]; } - (IBAction)changePin:(id)sender { } @end The current code is causing the app to crash, but the NSLog is show the results of the NSFetchRequest in the NSArray. I currently think that I am not formatting the results of the NSFetchRequest in the NSArray properly if I had to take a guess. The crash log looks like the following, 2013-06-26 16:49:24.219 KegCop[41233:c07] names: ( { username = blah; }, { username = chris; }, { username = root; } ) 2013-06-26 16:49:24.223 KegCop[41233:c07] -[NSKnownKeysDictionary1 isEqualToString:]: unrecognized selector sent to instance 0xe54d9a0 2013-06-26 16:49:24.223 KegCop[41233:c07] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSKnownKeysDictionary1 isEqualToString:]: unrecognized selector sent to instance 0xe54d9a0' First throw call stack:

    Read the article

  • Why does this code generate an error? [closed]

    - by user559601
    <link rel="search" type="application/opensearchdescription+xml" href="http://b.static.ak.fbcdn.net/rsrc.php/yJ/r/H2SSvhJMJA-.xml" title="" /> <link rel="shortcut icon" href="http://static.ak.fbcdn.net/rsrc.php/y7/r/5875srnzL-I.ico" /></head> <body class="WelcomePage UIPage_LoggedOut mac Locale_en_US"> <div id="FB_HiddenContainer" style="position:absolute; top:-10000px; width:0px; height:0px;" ></div> <div id="blueBar" class="loggedOut"></div> <div id="globalContainer"><div id="dialogContainer"></div><div id="dropmenu_container"></div> <div id="content" class="fb_content clearfix"><div ><!-- 2365fa3194ecdc0cab15721ce967a9f8663937c7 --> <div class="WelcomePage_Container"><div class="loggedout_menubar_container"><div class="clearfix loggedout_menubar"><a class="lfloat" href="/" title="Go to Home"><img class="fb_logo img" src="http://static.ak.fbcdn.net/rsrc.php/yp/r/kk8dc2UJYJ4.png" alt="Facebook logo" width="170" height="36" /></a><div class="rfloat"><div class="menu_login_container"><form method="POST" action="https://login.facebook.com/login.php?login_attempt=1" id="login_form" onsubmit="return Event.__inlineSubmit(this,event)"><input type="hidden" name="charset_test" value="&euro;,&acute;,€,´,?,?,?" /><input type="hidden" name="lsd" value="hEICz" autocomplete="off" /><input type="hidden" id="locale" name="locale" value="en_US" autocomplete="off" /><table cellspacing="0"><tr><td class="html7magic"><label for="email">Email</label></td><td class="html7magic"><label for="pass">Password</label></td></tr><tr><td><input type="text" class="inputtext" name="email" id="email" tabindex="1" /></td><td><input type="password" class="inputtext" name="pass" id="pass" tabindex="2" /></td><td><label class="uiButton uiButtonConfirm"><input value="Login" tabindex="4" type="submit" /></label></td></tr><tr><td class="login_form_label_field"><input type="checkbox" class="inputcheckbox" value="1" id="persistent" name="persistent" checked="1" /><input type="hidden" name="default_persistent" value="1" /><label id="label_persistent" for="persistent">Keep me logged in</label></td><td class="login_form_label_field"><a href="http://www.facebook.com/reset.php" rel="nofollow">Forgot your password?</a></td></tr></table><input type="hidden" name="charset_test" value="&euro;,&acute;,€,´,?,?,?" /><input type="hidden" id="lsd" name="lsd" value="hEICz" autocomplete="off" /></form> </div></div></div></div><div class="WelcomePage_MainSell"><div class="WelcomePage_MainSellCenter clearfix"><div class="WelcomePage_MainSellLeft"><div class="WelcomePage_MainMessage">Facebook helps you connect and share with the people in your life.</div><div class="WelcomePage_MainMap">&nbsp;</div></div><div class="WelcomePage_MainSellRight"><div class="WelcomePage_SignUpSection"><div class="WelcomePage_SignUpMessage"><div class="WelcomePage_SignUpHeadline">Sign Up</div><div class="WelcomePage_SignUpSubheadline">It's free, and always will be.</div></div><div class="WelcomePage_SimpleReg" id="registration_container"><div><noscript><div id="no_js_box"><h2>Javascript is disabled on your browser.</h2><p>Please enable JavaScript on your browser or upgrade to a Javascript-capable browser to register for Facebook.</p></div></noscript><div id="simple_registration_container" class="simple_registration_container"><div id="reg_box"><form method="post" id="reg" name="reg" onsubmit="return function(event)&#123;return false;&#125;.call(this,event)!==false &amp;&amp; Event.__inlineSubmit(this,event)"><input type="hidden" autocomplete="off" name="post_form_id" value="c3a2bed7243b9a85f53d69f23a38da9d" /><input type="hidden" name="lsd" value="hEICz" autocomplete="off" /><input type="hidden" autocomplete="off" id="reg_instance" name="reg_instance" value="bpgeTawHFSiHa5-7SR4gbif7" /><input type="hidden" autocomplete="off" id="locale" name="locale" value="en_US" /><input type="hidden" autocomplete="off" id="terms" name="terms" value="on" /><input type="hidden" autocomplete="off" id="abtest_registration_group" name="abtest_registration_group" value="1" /><input type="hidden" autocomplete="off" id="referrer" name="referrer" value="" /><input type="hidden" autocomplete="off" id="md5pass" name="md5pass" value="" /><input type="hidden" autocomplete="off" id="validate_mx_records" name="validate_mx_records" value="1" /><input type="hidden" autocomplete="off" id="ab_test_data" name="ab_test_data" value="" /><div id="reg_form_box" class="large_form"><table class="uiGrid editor" cellspacing="0" cellpadding="1"><tbody><tr><td class="label">First Name:</td><td><div class="field_container"><input type="text" class="inputtext" id="firstname" name="firstname" /></div></td></tr><tr><td class="label">Last Name:</td><td><div class="field_container"><input type="text" class="inputtext" id="lastname" name="lastname" /></div></td></tr><tr><td class="label">Your Email:</td><td><div class="field_container"><input type="text" class="inputtext" id="reg_email__" name="reg_email__" /></div></td></tr><tr><td class="label">Re-enter Email:</td><td><div class="field_container"><input type="text" class="inputtext" id="reg_email_confirmation__" name="reg_email_confirmation__" /></div></td></tr><tr><td class="label">New Password:</td><td><div class="field_container"><input type="password" class="inputtext" id="reg_passwd__" name="reg_passwd__" value="" /></div></td></tr><tr><td class="label">I am:</td><td><div class="field_container"><div class="hidden_elem"><select><option></option><option></option></select><select><option></option><option></option></select></div><select class="select" name="sex" id="sex"><option value="0">Select Sex:</option><option value="1">Female</option><option value="2">Male</option></select></div></td></tr><tr><td class="label">Birthday:</td><td><div class="field_container"> <select class="" id="birthday_month" name="birthday_month" onchange="return run_with(this, [&quot;editor&quot;], function() &#123;editor_date_month_change(this, &quot;birthday_day&quot;, &quot;birthday_year&quot;);&#125;);"><option value="-1">Month:</option><option value="1">Jan</option>

    Read the article

  • Where is my object allocation and memory leak in this iPhone/objective C code?

    - by Spottswoode
    Hello, I'm still a rookie when it comes to this programming gig and was wondering if someone could help me smooth out this code. Functionally, the code works great and does what I need it to do. But when I run the performance tool the allocation graph peaks, the CPU load is high, there's a leak(s), and I've also confirmed when running on my iPhone it seems noticeably slower then the rest of the components in my app. I'd appreciate any advice/tips/help anyone could give me. :) Thanks in advance! .h file // // Time_CalculatorViewController.h // Time Calculator // // Created by Adam Soloway on 2/19/10. // Copyright Legacy Pilots 2010. All rights reserved. // #import <UIKit/UIKit.h> @interface Time_CalculatorViewController : UIViewController { //BOOL moveViewUp; //CGFloat scrollAmount; IBOutlet UILabel *hoursLabel; IBOutlet UILabel *minutesLabel; IBOutlet UILabel *hoursDecimalLabel; IBOutlet UILabel *minutesDecimalLabel; IBOutlet UILabel *errorLabel; IBOutlet UITextField *minTextField1; IBOutlet UITextField *minTextField2; IBOutlet UITextField *minTextField3; IBOutlet UITextField *minTextField4; IBOutlet UITextField *minTextField5; IBOutlet UITextField *minTextField6; IBOutlet UITextField *minTextField7; IBOutlet UITextField *minTextField8; IBOutlet UITextField *minTextField9; IBOutlet UITextField *minTextField10; IBOutlet UITextField *hourTextField1; IBOutlet UITextField *hourTextField2; IBOutlet UITextField *hourTextField3; IBOutlet UITextField *hourTextField4; IBOutlet UITextField *hourTextField5; IBOutlet UITextField *hourTextField6; IBOutlet UITextField *hourTextField7; IBOutlet UITextField *hourTextField8; IBOutlet UITextField *hourTextField9; IBOutlet UITextField *hourTextField10; IBOutlet UIButton *resetAll; NSString *minutesString1; NSString *minutesString2; NSString *minutesString3; NSString *minutesString4; NSString *minutesString5; NSString *minutesString6; NSString *minutesString7; NSString *minutesString8; NSString *minutesString9; NSString *minutesString10; NSString *hoursString1; NSString *hoursString2; NSString *hoursString3; NSString *hoursString4; NSString *hoursString5; NSString *hoursString6; NSString *hoursString7; NSString *hoursString8; NSString *hoursString9; NSString *hoursString10; int hourDecimalNumber; int totalTime; int leftOverMinutes; int minuteNumber1; int minuteNumber2; int minuteNumber3; int minuteNumber4; int minuteNumber5; int minuteNumber6; int minuteNumber7; int minuteNumber8; int minuteNumber9; int minuteNumber10; int hourNumber1; int hourNumber2; int hourNumber3; int hourNumber4; int hourNumber5; int hourNumber6; int hourNumber7; int hourNumber8; int hourNumber9; int hourNumber10; } //- (void)scrollTheView:(BOOL)movedUp; - (void)calculateTime; - (IBAction)resetAllValues; @end .m file // // Time_CalculatorViewController.m // Time Calculator // // Created by Adam Soloway on 2/19/10. // Copyright Legacy Pilots 2010. All rights reserved. // #import "Time_CalculatorViewController.h" @implementation Time_CalculatorViewController - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { if( minTextField1.editing || minTextField2.editing || minTextField3.editing || minTextField4.editing || minTextField5.editing || minTextField6.editing || minTextField7.editing || minTextField8.editing || minTextField9.editing || minTextField10.editing || hourTextField1.editing || hourTextField2.editing || hourTextField3.editing || hourTextField4.editing || hourTextField5.editing || hourTextField6.editing || hourTextField7.editing || hourTextField8.editing || hourTextField9.editing || hourTextField10.editing) { [minTextField1 resignFirstResponder]; [minTextField2 resignFirstResponder]; [minTextField3 resignFirstResponder]; [minTextField4 resignFirstResponder]; [minTextField5 resignFirstResponder]; [minTextField6 resignFirstResponder]; [minTextField7 resignFirstResponder]; [minTextField8 resignFirstResponder]; [minTextField9 resignFirstResponder]; [minTextField10 resignFirstResponder]; [hourTextField1 resignFirstResponder]; [hourTextField2 resignFirstResponder]; [hourTextField3 resignFirstResponder]; [hourTextField4 resignFirstResponder]; [hourTextField5 resignFirstResponder]; [hourTextField6 resignFirstResponder]; [hourTextField7 resignFirstResponder]; [hourTextField8 resignFirstResponder]; [hourTextField9 resignFirstResponder]; [hourTextField10 resignFirstResponder]; [self calculateTime]; //if (moveViewUp) [self scrollTheView:NO]; } [super touchesBegan:touches withEvent:event]; } /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } /* // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [minutesString1 release]; [minutesString2 release]; [minutesString3 release]; [minutesString4 release]; [minutesString5 release]; [minutesString6 release]; [minutesString7 release]; [minutesString8 release]; [minutesString9 release]; [minutesString10 release]; [hoursString1 release]; [hoursString2 release]; [hoursString3 release]; [hoursString4 release]; [hoursString5 release]; [hoursString6 release]; [hoursString7 release]; [hoursString8 release]; [hoursString9 release]; [hoursString10 release]; [super dealloc]; } -(BOOL)textFieldShouldReturn:(UITextField *)theTextField { //[minTextField10 resignFirstResponder]; //if (moveViewUp) [self scrollTheView:NO]; [self calculateTime]; return YES; } - (IBAction)resetAllValues { minTextField1.text = 0; minTextField2.text = 0; minTextField3.text = 0; minTextField4.text = 0; minTextField5.text = 0; minTextField6.text = 0; minTextField7.text = 0; minTextField8.text = 0; minTextField9.text = 0; minTextField10.text = 0; hourTextField1.text = 0; hourTextField2.text = 0; hourTextField3.text = 0; hourTextField4.text = 0; hourTextField5.text = 0; hourTextField6.text = 0; hourTextField7.text = 0; hourTextField8.text = 0; hourTextField9.text = 0; hourTextField10.text = 0; totalTime = 0; leftOverMinutes = 0; hoursLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = 0; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; self.calculateTime; } - (void)calculateTime { minutesString1 = minTextField1.text; minutesString2 = minTextField2.text; minutesString3 = minTextField3.text; minutesString4 = minTextField4.text; minutesString5 = minTextField5.text; minutesString6 = minTextField6.text; minutesString7 = minTextField7.text; minutesString8 = minTextField8.text; minutesString9 = minTextField9.text; minutesString10 = minTextField10.text; hoursString1 = hourTextField1.text; hoursString2 = hourTextField2.text; hoursString3 = hourTextField3.text; hoursString4 = hourTextField4.text; hoursString5 = hourTextField5.text; hoursString6 = hourTextField6.text; hoursString7 = hourTextField7.text; hoursString8 = hourTextField8.text; hoursString9 = hourTextField9.text; hoursString10 = hourTextField10.text; minuteNumber1 = [minutesString1 intValue]; minuteNumber2 = [minutesString2 intValue]; minuteNumber3 = [minutesString3 intValue]; minuteNumber4 = [minutesString4 intValue]; minuteNumber5 = [minutesString5 intValue]; minuteNumber6 = [minutesString6 intValue]; minuteNumber7 = [minutesString7 intValue]; minuteNumber8 = [minutesString8 intValue]; minuteNumber9 = [minutesString9 intValue]; minuteNumber10 = [minutesString10 intValue]; hourNumber1 = ([hoursString1 intValue] * 60); hourNumber2 = ([hoursString2 intValue] * 60); hourNumber3 = ([hoursString3 intValue] * 60); hourNumber4 = ([hoursString4 intValue] * 60); hourNumber5 = ([hoursString5 intValue] * 60); hourNumber6 = ([hoursString6 intValue] * 60); hourNumber7 = ([hoursString7 intValue] * 60); hourNumber8 = ([hoursString8 intValue] * 60); hourNumber9 = ([hoursString9 intValue] * 60); hourNumber10 = ([hoursString10 intValue] * 60); totalTime = (hourNumber1 + hourNumber2 +hourNumber3 +hourNumber4 +hourNumber5 +hourNumber6 +hourNumber7 +hourNumber8 +hourNumber9 +hourNumber10 + minuteNumber1 + minuteNumber2 + minuteNumber3 + minuteNumber4 + minuteNumber5 +minuteNumber6 + minuteNumber7 + minuteNumber8 + minuteNumber9 + minuteNumber10); if (totalTime <= 59) { leftOverMinutes = totalTime; hoursLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = 0; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >59 && totalTime <= 119){ leftOverMinutes = totalTime - 60; hoursLabel.text = [NSString stringWithFormat:@"1"]; hourDecimalNumber = 1; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >119 && totalTime <= 179){ leftOverMinutes = totalTime - 120; hoursLabel.text = [NSString stringWithFormat:@"2"]; hourDecimalNumber = 2; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >179 && totalTime <= 239){ leftOverMinutes = totalTime - 180; hoursLabel.text = [NSString stringWithFormat:@"3"]; hourDecimalNumber = 3; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >239 && totalTime <= 299){ leftOverMinutes = totalTime - 240; hoursLabel.text = [NSString stringWithFormat:@"4"]; hourDecimalNumber = 4; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >299 && totalTime <= 359){ leftOverMinutes = totalTime - 300; hoursLabel.text = [NSString stringWithFormat:@"5"]; hourDecimalNumber = 5; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >359 && totalTime <= 419){ leftOverMinutes = totalTime - 360; hoursLabel.text = [NSString stringWithFormat:@"6"]; hourDecimalNumber = 6; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >419 && totalTime <= 479){ leftOverMinutes = totalTime - 420; hoursLabel.text = [NSString stringWithFormat:@"7"]; hourDecimalNumber = 7; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >479 && totalTime <= 539){ leftOverMinutes = totalTime - 480; hoursLabel.text = [NSString stringWithFormat:@"8"]; hourDecimalNumber = 8; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >539 && totalTime <= 599){ leftOverMinutes = totalTime - 540; hoursLabel.text = [NSString stringWithFormat:@"9"]; hourDecimalNumber = 9; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >599 && totalTime <= 659){ leftOverMinutes = totalTime - 600; hoursLabel.text = [NSString stringWithFormat:@"10"]; hourDecimalNumber = 10; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >659 && totalTime <= 719){ leftOverMinutes = totalTime - 660; hoursLabel.text = [NSString stringWithFormat:@"11"]; hourDecimalNumber = 11; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >719 && totalTime <= 779){ leftOverMinutes = totalTime - 720; hoursLabel.text = [NSString stringWithFormat:@"12"]; hourDecimalNumber = 12; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >779 && totalTime <= 839){ leftOverMinutes = totalTime - 780; hoursLabel.text = [NSString stringWithFormat:@"13"]; hourDecimalNumber = 13; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >839 && totalTime <= 899){ leftOverMinutes = totalTime - 840; hoursLabel.text = [NSString stringWithFormat:@"14"]; hourDecimalNumber = 14; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >899 && totalTime <= 959){ leftOverMinutes = totalTime - 900; hoursLabel.text = [NSString stringWithFormat:@"15"]; hourDecimalNumber = 15; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >959 && totalTime <= 1019){ leftOverMinutes = totalTime - 960; hoursLabel.text = [NSString stringWithFormat:@"16"]; hourDecimalNumber = 16; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1019 && totalTime <= 1079){ leftOverMinutes = totalTime - 1020; hoursLabel.text = [NSString stringWithFormat:@"17"]; hourDecimalNumber = 17; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1079 && totalTime <= 1139){ leftOverMinutes = totalTime - 1080; hoursLabel.text = [NSString stringWithFormat:@"18"]; hourDecimalNumber = 18; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1139 && totalTime <= 1199){ leftOverMinutes = totalTime - 1140; hoursLabel.text = [NSString stringWithFormat:@"19"]; hourDecimalNumber = 19; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1199 && totalTime <= 1259){ leftOverMinutes = totalTime - 1200; hoursLabel.text = [NSString stringWithFormat:@"20"]; hourDecimalNumber = 20; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1259 && totalTime <= 1319){ leftOverMinutes = totalTime - 1260; hoursLabel.text = [NSString stringWithFormat:@"21"]; hourDecimalNumber = 21; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1319 && totalTime <= 1379){ leftOverMinutes = totalTime - 1320; hoursLabel.text = [NSString stringWithFormat:@"22"]; hourDecimalNumber = 22; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1379 && totalTime <= 1439){ leftOverMinutes = totalTime - 1380; hoursLabel.text = [NSString stringWithFormat:@"23"]; hourDecimalNumber = 23; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1439 && totalTime <= 1499){ leftOverMinutes = totalTime - 1440; hoursLabel.text = [NSString stringWithFormat:@"24"]; hourDecimalNumber = 24; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1499 && totalTime <= 1559){ leftOverMinutes = totalTime - 1500; hoursLabel.text = [NSString stringWithFormat:@"25"]; hourDecimalNumber = 25; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1559 && totalTime <= 1619){ leftOverMinutes = totalTime - 1560; hoursLabel.text = [NSString stringWithFormat:@"26"]; hourDecimalNumber = 26; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1619 && totalTime <= 1679){ leftOverMinutes = totalTime - 1620; hoursLabel.text = [NSString stringWithFormat:@"27"]; hourDecimalNumber = 27; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1679 && totalTime <= 1739){ leftOverMinutes = totalTime - 1680; hoursLabel.text = [NSString stringWithFormat:@"28"]; hourDecimalNumber = 28; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1739 && totalTime <= 1799){ leftOverMinutes = totalTime - 1740; hoursLabel.text = [NSString stringWithFormat:@"29"]; hourDecimalNumber = 29; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1799 && totalTime <= 1859){ leftOverMinutes = totalTime - 1800; hoursLabel.text = [NSString stringWithFormat:@"30"]; hourDecimalNumber = 30; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; errorLabel.hidden = TRUE; } else if (totalTime >1859){ hoursLabel.text = [NSString stringWithFormat:@"Error"]; hoursDecimalLabel.text = [NSString stringWithFormat:@"Error"]; errorLabel.hidden = FALSE; } //Minutes Label if (leftOverMinutes < 10) { minutesLabel.text = [NSString stringWithFormat:@"0%d", leftOverMinutes]; } else minutesLabel.text = [NSString stringWithFormat:@"%d", leftOverMinutes]; //Minutes Decimal Label if (leftOverMinutes >=0 && leftOverMinutes <=2) { minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; } else if (leftOverMinutes >=3 && leftOverMinutes <=8){ minutesDecimalLabel.text = [NSString stringWithFormat:@"1"]; } else if (leftOverMinutes >=9 && leftOverMinutes <=14){ minutesDecimalLabel.text = [NSString stringWithFormat:@"2"]; } else if (leftOverMinutes >=15 && leftOverMinutes <=20){ minutesDecimalLabel.text = [NSString stringWithFormat:@"3"]; } else if (leftOverMinutes >=21 && leftOverMinutes <=26){ minutesDecimalLabel.text = [NSString stringWithFormat:@"4"]; } else if (leftOverMinutes >=27 && leftOverMinutes <=32){ minutesDecimalLabel.text = [NSString stringWithFormat:@"5"]; } else if (leftOverMinutes >=33 && leftOverMinutes <=38){ minutesDecimalLabel.text = [NSString stringWithFormat:@"6"]; } else if (leftOverMinutes >=39 && leftOverMinutes <=44){ minutesDecimalLabel.text = [NSString stringWithFormat:@"7"]; } else if (leftOverMinutes >=45 && leftOverMinutes <=50){ minutesDecimalLabel.text = [NSString stringWithFormat:@"8"]; } else if (leftOverMinutes >=51 && leftOverMinutes <=56){ minutesDecimalLabel.text = [NSString stringWithFormat:@"9"]; } else if (leftOverMinutes >=57 && leftOverMinutes <=60){ minutesDecimalLabel.text = [NSString stringWithFormat:@"0"]; hourDecimalNumber = hourDecimalNumber + 1; hoursDecimalLabel.text = [NSString stringWithFormat:@"%i", hourDecimalNumber]; } } @end

    Read the article

< Previous Page | 14 15 16 17 18