Search Results

Search found 372 results on 15 pages for 'uilabel'.

Page 14/15 | < Previous Page | 10 11 12 13 14 15  | Next Page >

  • NSDateFormatter iOS6 issue

    - by Angad Manchanda
    I have written a code for UIButton press to decrement date. The present date is shown in a UILabel text property and it changes to the previous date when the button is pressed. The following code works perfectly fine for iOS5 but doesn't work with iOS6. With iOS6, it gives the output as Dec 31, 1999 or null. - (IBAction)showPrevDate:(id)sender { NSString *dateForDecrement = _showDateLbl.text; [dateFormatter setDateFormat:@"MMM d, yyyy (EEE)"]; NSDate *dateObjectForDecrement = [dateFormatter dateFromString:dateForDecrement]; int subtractDays = 1; dateAfterDecrement=[dateObjectForDecrement dateByAddingTimeInterval:-(24*60*60 * subtractDays)]; _showDateLbl.text = [NSString stringWithFormat:@"%@", [dateFormatter stringFromDate:dateAfterDecrement]]; } Can anybody verify this, or tell me if its's a bug in iOS6 ? Thanks guys.

    Read the article

  • highlight scrolling text on iphone(about lyrics show )

    - by ????
    hi all, i'm in troubled show lyrics .i use uitextview show lyrics code snips IBOutlet UILabel *lrcshow; IBOutlet UITextView *showlrc; self.lrcshow.text = [lrcDictss objectForKey:[NSString stringWithFormat:@"%d",(int)self.player.currentTime]]; if (self.lrcshow.text!=nil) { NSRange selection = [self.showlrc.text rangeOfString:self.lrcshow.text]; if( selection.location != NSNotFound ) { showlrc.selectedRange = selection; } } lyrics line by line scrolling show,the problem is now playing(selectedRange) lyric is not highlight, i want this line highlight how can i code ? any suggestion?or use calayer ?cgcontext quartz core instead it? how can i code ? ps.use uitextview show is rigidly ,not smooth! lr style show pic url this is my app style: http://www.flickr.com/photos/53054715@N05/5359722887/ this is good style: flickr.com/photos/53054715@N05/5360345226/

    Read the article

  • Simple iPhone tally method question

    - by Rob
    Just trying to create a simple method that counts up 1 on the tally when the button is pressed. My knowledge is extremely limited and I am pretty sure that my problem is somewhere in the method implementation: -(IBAction) updateTally:(id) sender { NSString *text; int total = 0; total = total + 1; text=[[NSString alloc] initWithFormat: @"%i", total]; lblTally.text = text; } I have done the necessary interface declarations for the lblTally UILabel and the updateTally method. I suspect that there is some sort of an NSString/int/%i/%@ mixup that I am making but I'm not sure how to fix it. When I run the program as it currently is it displays a 0 in the lblTally label field on the iphone. When I press the button it then displays a 1 in that field. However, if I continue to press the button - nothing happens.

    Read the article

  • How to delete a customized cell in UITableView ?

    - 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 ? Thank you.

    Read the article

  • Is there a faster way to draw text?

    - by mystify
    Shark complains about a big performance hit with this line, which takes like 80% of CPU time. I have a counter that is updated very frequently and performance seriously sucks. It's an custom UILabel subclass with -drawRect: implemented. Every time the counter value changes, this is used to draw the new text: [self.text drawInRect:textRect withFont:correctedFont lineBreakMode:self.lineBreakMode alignment:self.textAlignment]; When I comment this line out, performance rocks. Its smooth and fast. So Shark isn't wrong about this. But what could I do to improve this? Maybe go a level deeper? Does that make any sense? Probably drawing text is really so incredible heavy...?

    Read the article

  • RTL shows numbers at the end of lines

    - by Tiger
    Hi. Trying to display a hebrew string that starts with a number, always displays the number at the end of the string like so: 1. ??? ???? ????? but I need the number to be displayed at the right side of the text- any solution to that? It happens with UILabel & UITextField & UITextView and trying to write the number at the left side also produce the same resault. Playing with combinations of UITextAlignment will doesn't help.

    Read the article

  • Placing text on UIView in custom location

    - by JAM
    I am trying to calculate a position to place label on the screen. The goal is to place "word" label in lower right corner of the first square block If yellowish square is defined as myView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 70, 70)]; [self.view addSubview:myView]; [myView setBackgroundColor:[UIColor colorWithHexString:@"FFFFEC"]]; Using it, i'd like to place a label in it's lower right corner l1 = [[UILabel alloc] init]; [l1 setText:@"word"]; [l1 setFrame:CGRectMake(myView.frame.origin.x + myView.frame.size.width, myView.frame.origin.y + myView.frame.size.height, 700, 700)]; [l1 setFont:[UIFont fontWithName:@"Arial" size:10.0]]; [l1 setBackgroundColor:[UIColor colorWithHexString:@"CCFFFEC"]]; [l1 setTextAlignment:UITextAlignmentRight]; [l1 sizeToFit]; This is what happens: The matter here obviously, is in a correct offset. Knowing the font and size of text, how can one correctly calculate it?

    Read the article

  • How should I set up UITableViewCell subclasses with UIControls in them?

    - by GeneralMike
    I have a dynamically generated UITableView (so I have to use prototype cells, not static cells) with many cells on it. Each cell will have a UILabel on it. Additionally, each cell will also have at least one UIControl (as of right now, it could be a UITextfield or a UISegmentedControl, but I want to keep it flexible in case I add something else in the future). I'm going to need to be able to send the text in that label, and get either the text in the textfield, or the title of the selected segment index, etc. For the cells with multiple controls, I'm going to have to also let it know what control I'm interested in for that call. What would be the best way to set this up?

    Read the article

  • Trouble with ID in NSString

    - by useboot
    I am trying to create something interesting in my application. So, I created an UILabel and I want to output new value. So, my code. NSString *test = @"13"; self.UserAge.text = @"Your age is %@", test; But it doesn't work. In Console-Command Mode I can do it with NSLog(); My result is "Your age is %@". But I need to output "Your age is 13". What do I should do with name? Sorry, if my question is easy for you. I am beginner. :) Thank you everyone who will answer on my question.

    Read the article

  • Autoresize UITextView and UIScrollView

    - by dennis3484
    Hello guys, I already did several searches on Stack Overflow and Google, but I couldn't find a solution to my problem. I have a Detail View for a product that includes a UIScrollView and a few subviews (UIImageView, UILabel, UITextView). You can find an example here. First I wanna autoresize the UITextView (not the text itself!) to the corresponding height. Then I wanna autoresize the entire UIScrollView so that it fits the height of my UITextView and the elements above it. I've tried the following code: myUITextView.frame = CGRectMake(2.0, 98.0, 316.0, self.view.bounds.size.height); [scrollView setContentOffset:CGPointMake(0.0, 0.0) animated:NO]; scrollView.contentSize = CGSizeMake(320.0, 98.0 + [myUITextView frame].size.height); [self.view addSubview:scrollView]; 98.0 + [myUITextView frame].size.height) because my thought was: After getting the height of myUITextView, add the height of the other subviews (98.0) to it. Unfortunately it doesn't work very well. Depending on the content of the UIScrollView, it is too short or too long. I did some logging with the result that the height of the UITextView is always the same: 2010-01-27 14:15:45.096 myApp[1362:207] [myUITextView frame].size.height: 367.000000 Thanks!

    Read the article

  • UITextField resignFirstResponder not working?

    - by Tejaswi Yerukalapudi
    I've double checked all the connections in the nib file. My code - // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"iphone_bg_login.png"]]; self.title = @"Login screen"; loginTxt = [[UITextField alloc] init]; pwdText = [[UITextField alloc] init]; loginFailedTxt = [[UILabel alloc] init]; loginBtn = [[UIButton alloc] init]; navAppDelegate = (NavAppDelegate *)[[UIApplication sharedApplication] delegate]; navAppDelegate.navController.navigationBarHidden = YES; //NSArray *subVs = (NSArray *) [self.view subviews]; [super viewDidLoad]; } I've used a subclass of UIView (UIControl) and added all the UI elements to it in the Interface builder.The UIControl's touchDown method is connected to backgroundTap method. -(IBAction) backgroundTap:(id) sender { [loginTxt resignFirstResponder]; [pwdText resignFirstResponder]; //[[UIApplication sharedApplication] becomeFirstResponder]; //[sender resignFirstResponder]; } So the keyboard isn't removed like it's supposed to. Not sure why. Thanks for the help! Teja.

    Read the article

  • Changing UITableViewCell textLabel background color to clear

    - by SorinA.
    In my app i have a table view with customViewCells. i subclassed the UITableViewCell class and added an image that will load async and for the text i use cell.textLabel.text = @"someThext". for the cells the background color is set alternatively to [UIColor darkGrayColor] and whitecolor. When i run the app in the simulator and on the pone the textLabel of the cell has the background white. I want to set it to be clear, because i want the background color of the cell to be full not a strip then white then another strip. in the init method of my custom cell i added hoping that the white will turn into red but it doesn't have any effect. [self.textLabel setBackgroundColor:[UIColor redColor]]; i tried also self.textLabel.backgroundColor = [UIColor redColor]; but this also didn't work...if i add a UILabel as a subview the background color of the label can be set..but i don't want to do that because when i rotate the phone i want my labels to auto enlarge... any ideas why setting the background color of cell.textLabel doesn't work? thank you

    Read the article

  • How to change rowHeight of a TableViewCell depending on Stringlength

    - by Jens Koehler
    I have a table with different entries, each with different length. The height of each row should fit, so it can show the whole string. I use the following code: //... cellForRowAtIndexPath if (row == 0) { cell = [tableView dequeueReusableCellWithIdentifier:@"affCell"]; //if (!cell) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"affCell"]autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.autoresizingMask = UIViewAutoresizingFlexibleHeight; affL = [[UILabel alloc] initWithFrame:CGRectZero]; affL.textAlignment = UITextAlignmentLeft; affL.autoresizingMask = UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:affL]; //} //declaration label affL.text = [fDictionary objectForKey:@"aff"]; affL.numberOfLines = 0; [affL sizeToFit]; affL.frame = CGRectMake(15.0, 10.0, 220.0, affL.frame.size.height); CGFloat affLH = affL.frame.size.height; [tableView setRowHeight:affLH+30]; I also use //... heightForRowAtIndexPath return affL.frame.size.height; How can I fix this problem?

    Read the article

  • Check if UINavigationItem title is truncated

    - by PartiallyFinite
    I want to check whether the title of a UINavigationItem is truncated. I set the title like this: self.navigationItem.title = whatever. I know I can check if the text in a UILabel is truncated like this: CGSize size = [label.text sizeWithFont:[UIFont fontWithName:@"myfont" size:18.0]]; if (size.width > label.bounds.size.width) { // set a shorter title } And I can even find the UINavigationItemView object in which the title is displayed like so: UIView *navItemView; for (UIView *view in self.navigationController.navigationBar.subviews) { if ([view isKindOfClass:NSClassFromString(@"UINavigationItemView")]) { navItemView = view; } } But I cannot apply this method to the navItemView because is always seems to have a width of exactly 58, which is much less than the title in it, so according to that, it would appear that the title is truncated, even when it isn't. So, my question comes down to this: How do I find the width of the title displayed in the UINavigationItem? UPDATE: I have found a solution to my problem, but it isn't exactly ideal, perfect, or reliable, so I am not marking it as an answer yet. If anyone has any better solutions, please share them.

    Read the article

  • How to customize the content of each page using Page Control and UIScrollView?

    - by viper15
    I have problem with customizing each page using pagecontrol and UIScrollView. I'm customizing Page Control from Apple. Basically I would like to have each page different with text and image alternately on different page. Page 1 will have all text, Page 2 will have just images, Page 3 will have all text and goes on. This is original code: // Set the label and background color when the view has finished loading. - (void)viewDidLoad { pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1]; self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber]; } As you can see, this code shows only Page 1, Page 2 etc as you scroll right. I tried to put in this new code but that didn't make any difference. There's no error. I know this is pretty simple code. I don't why it doesn't work. I declare pageText as UILabel. // Set the label and background color when the view has finished loading. - (void)viewDidLoad { pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1]; self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber]; if (pageNumber == 1) { pageText.text = @"Text in page 1"; } if (pageNumber == 2) { pageText.text = @"Image in page 2"; } if (pageNumber == 3) { pageText.text = @"Text in page 3"; } } I don't know why it doesn't work. Also if you have better way to do it, let me know. Thanks.

    Read the article

  • Using objective-c objects with an NSDictionary

    - by Mark
    I want store a URL against a UILabel so that when a user touches the label it takes them to that URL in a UIWebView. I have declared a NSDictionary like so: NSMutableArray *linksArray = [[NSMutableArray alloc] init]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem1ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem2ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem3ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem4ReadMoreLabel]]; [linksArray addObject: [NSValue valueWithNonretainedObject: newsItem5ReadMoreLabel]]; //NSString *ageLink = @"http://www.theage.com.au"; NSArray *defaultLinks = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", nil]; self.urlToLinkDictionary = [[NSMutableDictionary alloc] init]; self.urlToLinkDictionary = [NSDictionary dictionaryWithObjects:defaultLinks forKeys:linksArray]; Considering I used a NSValue as the key, how do I get/set the URL associated with that key given that I only have references to the UILabels? this is what I have but it doesn't work: for(NSValue *key in [self.urlToLinkDictionary allKeys]) { if ([key nonretainedObjectValue] == linkedLabel) { [self.urlToLinkDictionary setValue:[newsItem link] forKey: key]; } } but I get an error: "objc_exception_throw" resolved

    Read the article

  • Displaying timecode using NSTimer and NSDateFormatter

    - by Chris B
    Hi. I am very close to completing my first iphone app and it has been a joy. I am trying to add running timecode using the current time via an NSTimer displaying the current time (NSDate) on a UILabel. NSDate is working fine for me, showing hour, minute, second, milliseconds. But instead of milliseconds, I need to show 24 frames per second. The problem is that I need the frames per second to be synced 100% with the hour, minute and second, so I can't add the frames in a separate timer. I tried that and had it working but the frame timer was not running in sync with the date timer. Can anyone help me out with this? Is there a way to customize NSDateFormatter so that I can have a date timer formatted with 24 frames per second? Right now I'm limited to formatting just hours, minutes, seconds, and milliseconds. Here's the code I'm using right now -(void)runTimer { // This starts the timer which fires the displayCount method every 0.01 seconds runTimer = [NSTimer scheduledTimerWithTimeInterval: .01 target: self selector: @selector(displayCount) userInfo: nil repeats: YES]; } //This formats the timer using the current date and sets text on UILabels - (void)displayCount; { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; NSDate *date = [NSDate date]; // This will produce a time that looks like "12:15:07:75" using 4 separate labels // I could also have this on just one label but for now they are separated // This sets the Hour Label and formats it in hours [formatter setDateFormat:@"HH"]; [timecodeHourLabel setText:[formatter stringFromDate:date]]; // This sets the Minute Label and formats it in minutes [formatter setDateFormat:@"mm"]; [timecodeMinuteLabel setText:[formatter stringFromDate:date]]; // This sets the Second Label and formats it in seconds [formatter setDateFormat:@"ss"]; [timecodeSecondLabel setText:[formatter stringFromDate:date]]; //This sets the Frame Label and formats it in milliseconds //I need this to be 24 frames per second [formatter setDateFormat:@"SS"]; [timecodeFrameLabel setText:[formatter stringFromDate:date]]; }

    Read the article

  • Adding a custom subview (created in a xib) to a view controller's view - What am I doing wrong

    - by Fran
    I've created a view in a xib (with an activity indicator, a progress view and a label). Then I've created .h/.m files: #import <UIKit/UIKit.h> @interface MyCustomView : UIView { IBOutlet UIActivityIndicatorView *actIndicator; IBOutlet UIProgressView *progressBar; IBOutlet UILabel *statusMsg; } @end #import "MyCustomView.h" @implementation MyCustomView - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Initialization code } return self; } - (void)dealloc { [super dealloc]; } @end In IB, I set the file's owner and view identity to MyCustomView and connect the IBOutlet to the File's owner In MyViewController.m, I've: - (void)viewDidLoad { [super viewDidLoad]; UIView *subView = [[MyCustomView alloc] initWithFrame:myTableView.frame]; [subView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]]; [myTableView addSubview:subView]; [subView release]; } When I run the app, the view is added, but I can't see the label, the progress bar and the activity indicator. What am I doing wrong?

    Read the article

  • [iOS] becomeFirstResponder: automatically scroll to the UIControl that becomes first responder

    - by Manni
    I have a grouped UITableViewController with one section and many rows. Each cell consists of two elements: a UILabel with a description and a UITextField for an input. A form, I would say. On the bottom is a button "Next" the go to the next view. But before that, I validate the UITextField's: if the user hasn't filled a field, this field should get the focus, so that the user sees that he needs to enter something. I tried with this: [inputField becomeFirstResponder]; Remember, the button I pressed is on the bottom of my view and imagine that the UITextField is on the top. In this situation, the field doesn't get the focus because it is too far away. Now when I scroll up slowly and the field gets visible, the field becomes first responder and gets the cursor :-) Conclusion: The becomeFirstResponder worked, but does not exactly do what I wanted to. I don't want to scroll up with my finger, the field should get the focus and visible automatically. Is there any way to "jump" directly to my field? Use an alternative to becomeFirstResponder? Scroll to my field automatically? Thanks for your help!

    Read the article

  • iPhone slide view passing variables

    - by sebastyuiop
    Right, I'm trying to make an app that has a calculation that involves a stopwatch. When a button on the calculation view is clicked a stopwatch slides in from the bottom. This all works fine, the problem I can't get my head around is how to send the recorded time back to the previous controller to update a textfield. I've simplified the code and stripped out most irrelevant stuff. Many thanks. CalculationViewController.h #import <UIKit/UIKit.h> @interface CalculationViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { IBOutlet UITextField *inputTxt; } @property (nonatomic, retain) UITextField *inputTxt; - (IBAction)showTimer:(id)sender; @end CalculationViewController.m #import "CalculationViewController.h" #import "TimerViewController.h" @implementation CalculationViewController - (IBAction)showTimer:(id)sender { TimerViewController *timerView = [[TimerViewController alloc] init]; [self.navigationController presentModalViewController:timerView animated:YES]; } TimerViewController.h #import <UIKit/UIKit.h> @interface TimerViewController : UIViewController { IBOutlet UILabel *time; NSTimer *myTicker; } - (IBAction)start; - (IBAction)stop; - (IBAction)reset; - (void)showActivity; @end TimerViewController.m #import "TimerViewController.h" #import "CalculationViewController.h" @implementation TimerViewController - (IBAction)start { myTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(showActivity) userInfo:nil repeats:YES]; } - (IBAction)stop { [myTicker invalidate]; #Update inputTxt on calculation view here [self dismissModalViewControllerAnimated:YES]; } - (IBAction)reset { time.text = @"0"; } - (void)showActivity { int currentTime = [time.text intValue]; int newTime = currentTime + 1; time.text = [NSString stringWithFormat:@"%d", newTime]; } @end

    Read the article

  • iPhone SDK math - pythagorean theorem problem!

    - by Flafla2
    Just as a practice, I am working on an app that solves the famous middle school pythagorean theorem, a squared + b squared = c squared. Unfortunately, the out-coming answer has, in my eyes, nothing to do with the actual answer. Here is the code used during the "solve" action. - (IBAction)solve { int legoneint; int legtwoint; int hypotenuseint; int lonesq = legoneint * legoneint; int ltwosq = legtwoint * legtwoint; int hyposq = hypotenuseint * hypotenuseint; hyposq = lonesq + ltwosq; if ([legone.text isEqual:@""]) { legtwoint = [legtwo.text intValue]; hypotenuseint = [hypotenuse.text intValue]; answer.text = [NSString stringWithFormat:@"%d", legoneint]; self.view.backgroundColor = [UIColor blackColor]; } if ([legtwo.text isEqual:@""]) { legoneint = [legone.text intValue]; hypotenuseint = [hypotenuse.text intValue]; answer.text = [NSString stringWithFormat:@"%d", legtwoint]; self.view.backgroundColor = [UIColor blackColor]; } if ([hypotenuse.text isEqual:@""]) { legoneint = [legone.text intValue]; legtwoint = [legtwo.text intValue]; answer.text = [NSString stringWithFormat:@"%d", hypotenuseint]; self.view.backgroundColor = [UIColor blackColor]; } } By the way, legone, legtwo, and hypotenuse all represent the UITextField that corresponds to each mathematical part of the right triangle. Answer is the UILabel that tells, you guessed it, the answer. Does anyone see any flaws in the program? Thanks in advance!

    Read the article

  • Initializing Detail View from nib with parameters passed from Root View

    - by culov
    I'm have a map view with a number of annotations on it... once the callout is clicked, i need to pass several parameters to the DetailViewController, so ive been trying to do this through the constructor. I've debugged a bit and discovered that the arguments are being passed properly and are being received as expected within the constructor, but for some reason whenever I try to change the values of the IBOutlets I've positioned in the nib, it never has an effect. Here's what im passing (btw, im getting a "No initWithNibName : bundle : header' method found" warning at this line): DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil header:headerText]; [self.navigationController pushViewController:dvc animated:YES]; Now heres my constructor: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil header:(UILabel*)headerLabel { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { self.headerTextView = headerLabel; NSLog(@"header:%@", headerLabel.text); } return self; } Once again, the problem is that headerLabel.text is printed properly in the console, but the line self.headerTextView = headerLabel; doesnt seem to be doing what I want it to do. Thanks!

    Read the article

  • Detect and handle, or override, clicks on a navigation bar

    - by Henrik Erlandsson
    I have an app where I've pushed two items onto the navigation bar. The top item, which ends up as a 'back' button, should have the function to jump all the way back to the start page, which is a list of web news. The other one simply displays a logo. The boss wants a navigation bar look and feel but with a simple function, so the user can click around the news site, but always be able to jump to the news list page with just the one click. Is the only option to create a fixed navbar with two items in IB, so that I can connect an outlet to the clickable item - or is there some way to intercept clicks to the navbar to make a requestURL? touchesBegan or touchUpInside would be fine, but I've found no way of implementing that so far. It's okay if the whole navbar is clickable, I just need some hint how to make it happen. Add a transparent UIlabel on top and detect clicks for that, maybe? A bonus would be to hide the item in the 'back' position without popping it from the stack.

    Read the article

  • Why doesn't my UIViewController class keep track of an NSArray instance variable.

    - by TaoStoner
    Hey, I am new to Objective-C 2.0 and Xcode, so forgive me if I am missing something elementary here. Anyways, I am trying to make my own UIViewController class called GameView to display a new view. To work the game I need to keep track of an NSArray that I want to load from a plist file. I have made a method 'loadGame' which I want to load the correct NSArray into an instance variable. However it appears that after the method executes the instance variable loses track of the array. Its easier if I just show you the code.... @interface GameView : UIViewController { IBOutlet UIView *view IBOutlet UILabel *label; NSArray *currentGame; } -(IBOutlet)next; -(void)loadDefault; ... @implementation GameView - (IBOutlet)next{ int numElements = [currentGame count]; int r = rand() % numElements; NSString *myString = [currentGame objectAtIndex:(NSUInteger)r]; [label setText: myString]; } - (void)loadDefault { NSDictionary *games; NSString *path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathComponent:@"Games.plist"]; games = [NSDictionary dictionaryWithContentsOfFile:finalPath]; currentGame = [games objectForKey:@"Default"]; } when loadDefault gets called, everything runs perfectly, but when I try to use the currentGame NSArray later in the method call to next, currentGame appears to be nil. I am also aware of the memory management issues with this code. Any help would be appreciated with this problem.

    Read the article

  • How can I programmatically position a view using relative points?

    - by Steve Madsen
    What is the best way to position a view relative to the size of its superview, when the bounds of the superview are not yet known? I am trying to avoid hard-coding coordinates if it is at all possible. Perhaps this is silly, and if so, that's a perfectly acceptable answer. I've run into this many times when working with custom UI. The most recent example is that I'm trying to replace the UINavigationItem plain-text title with a custom view. I want that view to fill the superview, but in addition, I want a UIActivityIndicatorView on the right side, inset about 2 pixels and centered vertically. Here's the code: - (void) viewDidLoad { [super viewDidLoad]; customTitleView = [[UIView alloc] initWithFrame:CGRectZero]; customTitleView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; titleLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; titleLabel.lineBreakMode = UILineBreakModeWordWrap; titleLabel.numberOfLines = 2; titleLabel.minimumFontSize = 11.0; titleLabel.font = [UIFont systemFontOfSize:17.0]; titleLabel.adjustsFontSizeToFitWidth = YES; [customTitleView addSubview:titleLabel]; spinnerView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; spinnerView.center = CGPointMake(customTitleView.bounds.size.width - (spinnerView.bounds.size.width / 2) - 2, customTitleView.bounds.size.height / 2); spinnerView.hidesWhenStopped = YES; [customTitleView addSubview:spinnerView]; self.navigationItem.titleView = customTitleView; [customTitleView release]; } Here's my problem: at the time that this code runs, customTitleView.bounds is still zeroes. The auto-resizing mask hasn't had a chance to do its thing yet, but I very much want those values so that I can compute the relative positions of other sub-views (here, the activity indicator). Is this possible without being ugly?

    Read the article

< Previous Page | 10 11 12 13 14 15  | Next Page >