Search Results

Search found 213 results on 9 pages for 'uitextview'.

Page 9/9 | < Previous Page | 5 6 7 8 9 

  • How do I locate the CGRect for a substring of text in a UILabel?

    - by bryanjclark
    For a given NSRange, I'd like to find a CGRect in a UILabel that corresponds to the glyphs of that NSRange. For example, I'd like to find the CGRect that contains the word "dog" in the sentence "The quick brown fox jumps over the lazy dog." The trick is, the UILabel has multiple lines, and the text is really attributedText, so it's a bit tough to find the exact position of the string. The method that I'd like to write on my UILabel subclass would look something like this: - (CGRect)rectForSubstringWithRange:(NSRange)range; Details, for those who are interested: My goal with this is to be able to create a new UILabel with the exact appearance and position of the UILabel, that I can then animate. I've got the rest figured out, but it's this step in particular that's holding me back at the moment. What I've done to try and solve the issue so far: I'd hoped that with iOS 7, there'd be a bit of Text Kit that would solve this problem, but most every example I've seen with Text Kit focuses on UITextView and UITextField, rather than UILabel. I've seen another question on Stack Overflow here that promises to solve the problem, but the accepted answer is over two years old, and the code doesn't perform well with attributed text. I'd bet that the right answer to this involves one of the following: Using a standard Text Kit method to solve this problem in a single line of code. I'd bet it would involve NSLayoutManager and textContainerForGlyphAtIndex:effectiveRange Writing a complex method that breaks the UILabel into lines, and finds the rect of a glyph within a line, likely using Core Text methods. My current best bet is to take apart @mattt's excellent TTTAttributedLabel, which has a method that finds a glyph at a point - if I invert that, and find the point for a glyph, that might work. Update: Here's a github gist with the three things I've tried so far to solve this issue: https://gist.github.com/bryanjclark/7036101

    Read the article

  • iphone twitter posting

    - by user313100
    I have some twitter code I modified from: http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/ His code used view alerts to login and post to twitter but I wanted to change mine to use windows. It is mostly working and I can login and post to Twitter. However, when I try to post a second time, the program crashes with a: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSCFString text]: unrecognized selector sent to instance 0xc2d560' I'm a bit of a coding newbie so any help would be appreciated. If I need to post more code, ask. #import "TwitterController.h" #import "xmacros.h" #define XAGENTS_TWITTER_CONFIG_FILE DOC_PATH(@"xagents_twitter_conifg_file.plist") static TwitterController* agent; @implementation TwitterController BOOL isLoggedIn; @synthesize parentsv, sharedLink; -(id)init { self = [super init]; maxCharLength = 140; parentsv = nil; isLogged = NO; isLoggedIn = NO; txtMessage = [[UITextView alloc] initWithFrame:CGRectMake(30, 225, 250, 60)]; UIImageView* bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fb_message_bg.png"]]; bg.frame = txtMessage.frame; lblCharLeft = [[UILabel alloc] initWithFrame:CGRectMake(15, 142, 250, 20)]; lblCharLeft.font = [UIFont systemFontOfSize:10.0f]; lblCharLeft.textAlignment = UITextAlignmentRight; lblCharLeft.textColor = [UIColor whiteColor]; lblCharLeft.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; txtUsername = [[UITextField alloc]initWithFrame:CGRectMake(125, 190, 150, 30)]; txtPassword = [[UITextField alloc]initWithFrame:CGRectMake(125, 225, 150, 30)]; txtPassword.secureTextEntry = YES; lblId = [[UILabel alloc]initWithFrame:CGRectMake(15, 190, 100, 30)]; lblPassword = [[UILabel alloc]initWithFrame:CGRectMake(15, 225, 100, 30)]; lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(80, 170, 190, 30)]; lblId.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; lblPassword.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; lblTitle.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; lblId.textColor = [UIColor whiteColor]; lblPassword.textColor = [UIColor whiteColor]; lblTitle.textColor = [UIColor whiteColor]; txtMessage.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; lblId.text = @"Username:"; lblPassword.text =@"Password:"; lblTitle.text = @"Tweet This Message"; lblId.textAlignment = UITextAlignmentRight; lblPassword.textAlignment = UITextAlignmentRight; lblTitle.textAlignment = UITextAlignmentCenter; txtUsername.borderStyle = UITextBorderStyleRoundedRect; txtPassword.borderStyle = UITextBorderStyleRoundedRect; txtMessage.delegate = self; txtUsername.delegate = self; txtPassword.delegate = self; login = [[UIButton alloc] init]; login = [UIButton buttonWithType:UIButtonTypeRoundedRect]; login.frame = CGRectMake(165, 300, 100, 30); [login setTitle:@"Login" forState:UIControlStateNormal]; [login addTarget:self action:@selector(onLogin) forControlEvents:UIControlEventTouchUpInside]; cancel = [[UIButton alloc] init]; cancel = [UIButton buttonWithType:UIButtonTypeRoundedRect]; cancel.frame = CGRectMake(45, 300, 100, 30); [cancel setTitle:@"Back" forState:UIControlStateNormal]; [cancel addTarget:self action:@selector(onCancel) forControlEvents:UIControlEventTouchUpInside]; post = [[UIButton alloc] init]; post = [UIButton buttonWithType:UIButtonTypeRoundedRect]; post.frame = CGRectMake(165, 300, 100, 30); [post setTitle:@"Post" forState:UIControlStateNormal]; [post addTarget:self action:@selector(onPost) forControlEvents:UIControlEventTouchUpInside]; back = [[UIButton alloc] init]; back = [UIButton buttonWithType:UIButtonTypeRoundedRect]; back.frame = CGRectMake(45, 300, 100, 30); [back setTitle:@"Back" forState:UIControlStateNormal]; [back addTarget:self action:@selector(onCancel) forControlEvents:UIControlEventTouchUpInside]; loading1 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; loading1.frame = CGRectMake(140, 375, 40, 40); loading1.hidesWhenStopped = YES; [loading1 stopAnimating]; loading2 = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; loading2.frame = CGRectMake(140, 375, 40, 40); loading2.hidesWhenStopped = YES; [loading2 stopAnimating]; twitterWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [twitterWindow addSubview:txtUsername]; [twitterWindow addSubview:txtPassword]; [twitterWindow addSubview:lblId]; [twitterWindow addSubview:lblPassword]; [twitterWindow addSubview:login]; [twitterWindow addSubview:cancel]; [twitterWindow addSubview:loading1]; UIImageView* logo = [[UIImageView alloc] initWithFrame:CGRectMake(35, 165, 48, 48)]; logo.image = [UIImage imageNamed:@"Twitter_logo.png"]; [twitterWindow addSubview:logo]; [logo release]; twitterWindow2 = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; [twitterWindow2 addSubview:lblTitle]; [twitterWindow2 addSubview:lblCharLeft]; [twitterWindow2 addSubview:bg]; [twitterWindow2 addSubview:txtMessage]; [twitterWindow2 addSubview:lblURL]; [twitterWindow2 addSubview:post]; [twitterWindow2 addSubview:back]; [twitterWindow2 addSubview:loading2]; [twitterWindow2 bringSubviewToFront:txtMessage]; UIImageView* logo1 = [[UIImageView alloc] initWithFrame:CGRectMake(35, 155, 42, 42)]; logo1.image = [UIImage imageNamed:@"twitter-logo-twit.png"]; [twitterWindow2 addSubview:logo1]; [logo1 release]; twitterWindow.hidden = YES; twitterWindow2.hidden = YES; return self; } -(void) onStart { [[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait]; twitterWindow.hidden = NO; [twitterWindow makeKeyWindow]; [self refresh]; if(isLogged) { twitterWindow.hidden = YES; twitterWindow2.hidden = NO; [twitterWindow2 makeKeyWindow]; } } - (void)textFieldDidBeginEditing:(UITextField *)textField { [textField becomeFirstResponder]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return NO; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ const char* str = [text UTF8String]; int s = str[0]; if(s!=0) if((range.location + range.length) > maxCharLength){ return NO; }else{ int left = 139 - ([sharedLink length] + [textView.text length]); lblCharLeft.text= [NSString stringWithFormat:@"%d",left]; // this fix was done by Jackie //http://amanpages.com/sample-iphone-example-project/twitteragent-tutorial-tweet-from-iphone-app-in-one-line-code-with-auto-tinyurl/#comment-38026299 if([text isEqualToString:@"\n"]){ [textView resignFirstResponder]; return FALSE; }else{ return YES; } } int left = 139 - ([sharedLink length] + [textView.text length]); lblCharLeft.text= [NSString stringWithFormat:@"%d",left]; return YES; } -(void) onLogin { [loading1 startAnimating]; NSString *postURL = @"http://twitter.com/statuses/update.xml"; NSString *myRequestString = [NSString stringWithFormat:@""]; NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ]; NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:postURL ] ]; [ request setHTTPMethod: @"POST" ]; [ request setHTTPBody: myRequestData ]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (!theConnection) { UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Failed to Connect to twitter" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; [aler show]; [aler release]; } [request release]; } -(void) onCancel { [[NSUserDefaults standardUserDefaults] setValue:@"NotActive" forKey:@"Twitter"]; twitterWindow.hidden = YES; [[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]; } -(void) onPost { [loading2 startAnimating]; NSString *postURL = @"http://twitter.com/statuses/update.xml"; NSString *myRequestString; if(sharedLink){ myRequestString = [NSString stringWithFormat:@"&status=%@",[NSString stringWithFormat:@"%@\n%@",txtMessage.text,sharedLink]]; }else{ myRequestString = [NSString stringWithFormat:@"&status=%@",[NSString stringWithFormat:@"%@",txtMessage.text]]; } NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString UTF8String ] length: [ myRequestString length ] ]; NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:postURL ] ]; [ request setHTTPMethod: @"POST" ]; [ request setHTTPBody: myRequestData ]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (!theConnection) { UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Failed to Connect to twitter" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; [aler show]; [aler release]; } [request release]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { // release the connection, and the data object [connection release]; if(isAuthFailed){ UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Login Failed" message:@"Invalid ID/Password" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; [aler show]; [aler release]; }else{ UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Connection Failed" message:@"Failed to connect to Twitter" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; [aler show]; [aler release]; } isAuthFailed = NO; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { isAuthFailed = NO; [loading1 stopAnimating]; [loading2 stopAnimating]; if(isLogged) { UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Twitter" message:@"Tweet Posted!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil]; [aler show]; [aler release]; txtMessage = @""; [self refresh]; } else { twitterWindow.hidden = YES; twitterWindow2.hidden = NO; [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyTwitterLoggedIn" object:nil userInfo:nil]; } isLogged = YES; isLoggedIn = YES; } -(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSDictionary* config = [NSDictionary dictionaryWithObjectsAndKeys:txtUsername.text,@"username",txtPassword.text,@"password",nil]; [config writeToFile:XAGENTS_TWITTER_CONFIG_FILE atomically:YES]; if ([challenge previousFailureCount] == 0) { NSURLCredential *newCredential; newCredential=[NSURLCredential credentialWithUser:txtUsername.text password:txtPassword.text persistence:NSURLCredentialPersistenceNone]; [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; } else { isAuthFailed = YES; [[challenge sender] cancelAuthenticationChallenge:challenge]; } } -(void) refresh { NSDictionary* config = [NSDictionary dictionaryWithContentsOfFile:XAGENTS_TWITTER_CONFIG_FILE]; if(config){ NSString* uname = [config valueForKey:@"username"]; if(uname){ txtUsername.text = uname; } NSString* pw = [config valueForKey:@"password"]; if(pw){ txtPassword.text = pw; } } } + (TwitterController*)defaultAgent{ if(!agent){ agent = [TwitterController new]; } return agent; } -(void)dealloc { [super dealloc]; [txtMessage release]; [txtUsername release]; [txtPassword release]; [lblId release]; [lblPassword release]; [lblURL release]; [twitterWindow2 release]; [twitterWindow release]; } @end

    Read the article

  • How to handle HTML Strings in Cocoa Touch

    - by balexandre
    I'm using a RSS Reader and works fine when I tap the UITableViewCell to load the <link> either in a UIWebView or to open Safari on that link. But I really want to learn how to load the Topic content into the application instead showing the entire site or jump to Safari In the RSS feed per each <item> there is a <body> tag (and a <Description> that contains the same but encoded) that contains the topic content, like the image below shows: So, instead of catching the <link> I'm assigning the <body>. Problem is that it does not work correctly :-( for this example I only get the content until the first <br> nothing more. I'm using a NSString as I would use in C#, should I use any other object, is there a better object to use on such data? Should I use an UITextView to load this information (as it has scroll already) or I should use a UIWebView instead? Thank you.

    Read the article

  • iphone menu navigation with buttons help requested

    - by David
    Hi, I'm trying to program an iphone app that will have several different (sub)apps. Ideally, I want to know how to make the main menu for this app look and behave like the iphone's own app menu, but I can't figure it out. If any one knows a package or library that does this, please let me know. Plan B is to mock one using UIButtons, and here is where I'm having problems. Basically, when I press a button that should push a new view, it calls the push method, but I still see the top view. in the app delegate, I have something like: AppViewController *viewController; App1ViewController *app1ViewController; UINavigationController *navController; and in didFinishLaunching method, something like: viewController = [ [ AppViewController alloc ] initWithAppDelegate: self ]; app1ViewController = [ [App1ViewController alloc ] initWithAppDelegate: self ]; navController = [ [ UINavigationController alloc ] initWithRootViewController:viewController]; [window addSubview:viewController.view]; and 2 methods -(void)app1{[ navController pushViewController: app1ViewController animated:YES ];} -(void)back{[ navController popViewControllerAnimated:YES ];} then I have 2 viewcontrollers in AppViewController.h @interface AppViewController : UIViewController { UINavigationController *navController; UIButton *appbtn1, *appbtn2, *appbtn3, *appbtn4; } -(id)initWithAppDelegate:(id)appDelegate; @end @interface App1ViewController : UIViewController { UITextView *textView; UINavigationController *navController; } -(id)initWithAppDelegate:(id)appDelegate; @end and define a loadView for each viewcontroller. However, when I press the app1 button and the app1 method gets called, it says the view hasa been pushed, but my view remains the buttons view, i.e. the root view. If I press the button again, it tells me I can't repush the app1view, the one I can't see. Any ideas? I can post the full code if that helps. Thank you for your time.

    Read the article

  • Why do I get "file is not of required architecture" when I try to build my app on an iphone?

    - by Dale
    My app seemingly runs fine in the simulator but the first time I hooked a phone up to my system and had it build for it I got a huge error log with things like: Build SCCUI of project SCCUI with configuration Debug CompileXIB HandleAlert.xib cd /Users/gdbriggs/Desktop/SCCUI setenv IBC_MINIMUM_COMPATIBILITY_VERSION 3.1 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr /bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/usr/bin/ibtool --errors --warnings --notices --output-format human-readable-text --compile /Users/gdbriggs/Desktop/SCCUI/build/Debug-iphoneos/SCCUI.app/HandleAlert.nib /Users/gdbriggs/Desktop/SCCUI/HandleAlert.xib /* com.apple.ibtool.document.warnings */ /Users/gdbriggs/Desktop/SCCUI/HandleAlert.xib:13: warning: UITextView does not support data detectors when the text view is editable. Ld build/Debug-iphoneos/SCCUI.app/SCCUI normal armv6 cd /Users/gdbriggs/Desktop/SCCUI setenv IPHONEOS_DEPLOYMENT_TARGET 3.1 setenv MACOSX_DEPLOYMENT_TARGET 10.5 setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk -L/Users/gdbriggs/Desktop/SCCUI/build/Debug-iphoneos -F/Users/gdbriggs/Desktop/SCCUI/build/Debug-iphoneos -F/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/System/Library/Frameworks -filelist /Users/gdbriggs/Desktop/SCCUI/build/SCCUI.build/Debug-iphoneos/SCCUI.build/Objects-normal/armv6/SCCUI.LinkFileList -mmacosx-version-min=10.5 -dead_strip -miphoneos-version-min=3.1 -framework Foundation -framework UIKit -framework CoreGraphics -framework MessageUI -o /Users/gdbriggs/Desktop/SCCUI/build/Debug-iphoneos/SCCUI.app/SCCUI ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/System/Library/Frameworks/Foundation.framework/Foundation, file is not of required architecture ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/System/Library/Frameworks/UIKit.framework/UIKit, file is not of required architecture ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics, file is not of required architecture ld: warning: in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/System/Library/Frameworks/MessageUI.framework/MessageUI, file is not of required architecture Undefined symbols: "_OBJC_CLASS_$_UIDevice", referenced from: __objc_classrefs__DATA@0 in SCAuthenticationHandler.o "_OBJC_CLASS_$_NSString", referenced from: __objc_classrefs__DATA@0 in CCProxy.o __objc_classrefs__DATA@0 in AlertSummaryViewController.o __objc_classrefs__DATA@0 in HomeLevelController.o __objc_classrefs__DATA@0 in SCAuthenticationHandler.o __objc_classrefs__DATA@0 in SCRequestHandler.o "_UIApplicationMain", referenced from: _main in main.o "_objc_msgSend", referenced from: _main in main.o _main in main.o _main in main.o -[SCCUIAppDelegate applicationDidFinishLaunching:] in and it just keeps going. At / near the bottom it says: ld: symbol(s) not found collect2: ld returned 1 exit status What am I doing wrong?

    Read the article

  • My app crashes after multiple rotates

    - by Ian Rae
    My app is crashing when I try and rotate it more than a couple of times. I first thought it was just the iPhone Simulator, so I loaded the app onto an iPod touch, and it crashed after fewer rotates in a row. I suspect it's a memory leak in one of my rotate methods. The only place I can think that the crash is being caused is in willRotateToInterfaceOrientation:duration:. The only two methods related to rotate that I've added/extended are shouldAutorotateToInterfaceOrientation: and willRotateToInterfaceOrientation:duration and I don't think it's the first because it only contains the two words: return YES;. Here is my willRotateToInterfaceOrientation:duration: method so you can review it and see where the possible memory leak is. -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration { UIFont *theFont; if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) { theFont = [yearByYear.font fontWithSize:16.0]; yearByYear.font = theFont; [theview setContentSize:CGSizeMake(460.0f, 635.0f)]; } else { theFont = [yearByYear.font fontWithSize:10.0]; yearByYear.font = theFont; [theview setContentSize:CGSizeMake(300.0f, 460.0f)]; } [theFont release]; } yearByYear is a UITextView theview is a UIScrollView if anyone has any idea of why my app is crashing, I would be greatly appreciative.

    Read the article

  • Only last row in method execute (Objective-C)

    - by Emil
    First I want to apologize for my lack of knowledge in programming in general. I am in the way of learning and have discovered that this site is a huge compliment for me of doing so. I have created a program with three UITextField(thePlace,theVerb,theOutput) and two UITextView where one of the textviews(theOutput) take the text from the other textview(theTemplate) and replaces some strings with the text entered in the textfields. When I click a button it triggers the method createStory that is listed below. This works fine with one exception. The text in the output only changes the string 'number' to the text in the textfield. However if I change the order in the method to replace 'place','number','verb' only the verb is changed, not the number. Im sure this is some sort of easy fix but I can't find it. Can some of you help me with my troubleshooting? - (IBAction)createStory:(id)sender { theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<place>" withString:thePlace.text]; theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<verb>" withString:theVerb.text]; theOutput.text=[theTemplate.text stringByReplacingOccurrencesOfString:@"<number>" withString:theNumber.text]; } Many thanks // Emil

    Read the article

  • How do I resize table view after resizing it's footer?

    - by Pedro
    I have a UITableView with header & footer added with code following the pattern shown in Apple's recipes example so the code for the footer is... if (tableFooterView == nil) { [[NSBundle mainBundle] loadNibNamed:@"DetailFooterView" owner:self options:nil]; self.tableView.tableFooterView = tableFooterView; } The footer NIB contains nothing more than a UITextView & I set text & resize with... CGSize size = [footerText sizeWithFont:[footerTextView font] constrainedToSize:CGSizeMake(304.0, 500.0)]; CGRect frame = CGRectMake(8.0, 0.0, size.width, size.height + 24.0); footerTextView.frame = frame; footerTextView.text = footerText; [tableFooterView sizeToFit]; That all works however I can't get the UITableView to resize around the resized footer. If I set the original size of the footer for any possible text I have a big whitespace in most cases. If I set it smaller then I can push the view up to see the whole text but it bounces back on release. I've tried [[self view] sizeToFit]; but that doesn't work. Can anyone fill me in? Cheers & TIA, Pedro :)

    Read the article

  • View isn't scrolling back down after I dismiss the keyboard

    - by fmi
    I have a Tab Bar app. One of the views has a UITextView that is hidden by the keyboard when touched. I've set the view to scroll to account for the keyboard but it the view doesn't always return to it's original position after I dismiss the keyboard. Here is my code: //Scroll the view for keyboard - (void)viewWillAppear:(BOOL)animated { void (^keyBoardWillShow) (NSNotification *)= ^(NSNotification * notif) { NSDictionary* info = [notif userInfo]; NSValue* aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; CGSize keyboardSize = [aValue CGRectValue].size; float bottomPoint = (additionalView.frame.origin.y + additionalView.frame.size.height + 10); scrollAmount = keyboardSize.height - (self.view.frame.size.height - bottomPoint); if (scrollAmount > 0) { moveViewUp =YES; [self scrollTheView:YES]; } else moveViewUp = NO; }; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:self.view.window queue:nil usingBlock:keyBoardWillShow]; void (^keyBoardWillHide) (NSNotification *)= ^(NSNotification * notif) { if (moveViewUp) [self scrollTheView:NO]; }; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:self.view.window queue:nil usingBlock:keyBoardWillHide]; [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; [super viewWillDisappear:animated]; } (void)scrollTheView:(BOOL)movedUp { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; CGRect rect = self.view.frame; if (movedUp){ rect.origin.y -= scrollAmount; } else { rect.origin.y += scrollAmount; } self.view.frame = rect; [UIView commitAnimations]; }

    Read the article

  • Understanding Basic Prototyping & Updating Key/Value pairs

    - by JordanD
    First time poster, long time lurker. I'm trying to learn some more advanced features of .js, and have two ojectives based on the pasted code below: I would like to add methods to a parent class in a specific way (by invoking prototype). I intend to update the declared key/value pairs each time I make an associated method call. execMTAction as seen in TheSuper will execute each function call, regardless. This is by design. Here is the code: function TheSuper(){ this.options = {componentType: "UITabBar", componentName: "Visual Browser", componentMethod: "select", componentValue: null}; execMTAction(this.options.componentType, this.options.componentName, this.options.componentMethod, this.options.componentValue); }; TheSuper.prototype.tapUITextView = function(val1, val2){ this.options = {componentType: "UITextView", componentName: val1, componentMethod: "entertext", componentValue: val2}; }; I would like to execute something like this (very simple): theSuper.executeMTAction(); theSuper.tapUITextView("a", "b"); Unfortunately I am unable to overwrite the "this.options" in the parent, and the .tapUITextView method throws an error saying it cannot find executeMTAction. All I want to do, like I said, is to update the parameters in the parent, then have executeMTAction run each time I make any method call. That's it. Any thoughts? I understand this is basic but I'm coming from a long-time procedural career and .js seems to have this weird confluence of oo/procedural that I'm having a bit of difficulty with. Thanks for any input!

    Read the article

  • App crashes after a few seconds

    - by Declan Scott
    when i launch my app, on trying to do something, it will crash after a couple of seconds. I have warnings of warning: incorrect implementation of "downloadTextViewCOntroller. I also have "method definiton for -timerFinished not found and"method definiton for -timerFinished not found" this is my .m plese help me. the .h is also t the bottom // // downloadTextViewController.m // downloadText // // Created by Declan Scott on 18/03/10. // Copyright MyCompanyName 2010. All rights reserved. // #import "downloadTextViewController.h" @implementation downloadTextViewController @synthesize start; -(IBAction)tapit { start.hidden = YES; } -(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { if (fabsf(acceleration.x) 2.0 || fabsf(acceleration.y) 2.0 || fabsf(acceleration.z) 2.0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"This app was developed by Declan Scott and demonstrates NSURLConnection and NSMutableData" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } } (NSString *) saveFilePath { NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"savedddata.plist"]; } (void)applicationWillTerminate:(UIApplication *)application { NSArray *values = [[NSArray alloc] initWithObjects:textView.text,nil]; [values writeToFile:[self saveFilePath] atomically:YES]; [values release]; } (void)viewDidLoad { UIAccelerometer *accelerometer = [UIAccelerometer sharedAccelerometer]; accelerometer.delegate = self; accelerometer.updateInterval = 1.0f/60.0f; NSString *myPath = [self saveFilePath]; NSLog(myPath); BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath]; if (fileExists) { NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath]; textView.text = [values objectAtIndex:0]; [values release]; } // notification UIApplication *myApp = [UIApplication sharedApplication]; // add yourself to the dispatch table [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:myApp]; [super viewDidLoad]; } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (IBAction)fetchData { loadingAlert = [[UIAlertView alloc] initWithTitle:@"Loading…\n\n\n\n" message:nil delegate:self cancelButtonTitle:@"Cancel Timer" otherButtonTitles:nil]; [loadingAlert show]; UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; activityView.frame = CGRectMake(139.0f-18.0f, 60.0f, 37.0f, 37.0f); [loadingAlert addSubview:activityView]; [activityView startAnimating]; timer = [NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:@selector(timerFinished) userInfo:nil repeats:NO]; NSURLRequest *downloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://simpsonatyapps.com/exampletext.txt"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:1.0]; NSURLConnection *downloadConnection = [[NSURLConnection alloc] initWithRequest:downloadRequest delegate:self]; if (downloadConnection) downloadedData = [[NSMutableData data] retain]; else { // Error } } (void)connection:(NSURLConnection *)downloadConnection didReceiveData:(NSData *)data { [downloadedData appendData:data]; NSString *file = [[NSString alloc] initWithData:downloadedData encoding:NSUTF8StringEncoding]; textView.text = file; // get rid of alert [loadingAlert dismissWithClickedButtonIndex:-1 animated:YES]; [loadingAlert release]; /// add badge [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1]; } (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 { [super dealloc]; } (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { return nil; } @end // // downloadTextViewController.h // downloadText // // Created by Declan Scott on 18/03/10. // Copyright MyCompanyName 2010. All rights reserved. // import @interface downloadTextViewController : UIViewController { IBOutlet UITextView *textView; NSMutableData *downloadedData; UIAlertView *loadingAlert; NSTimer *timer; IBOutlet UIButton *start; } - (IBAction)fetchData; - (IBAction)tapIt; - (void)timerFinished; @property (nonatomic, retain) UIButton *start; @end

    Read the article

  • Problem with SIngleton Class

    - by zp26
    Hi, I have a prblem with my code. I have a viewController and a singleton class. When i call the method readXml and run a for my program update the UITextView. When i call the clearTextView method the program exit with EXC_BAD_ACCESS. The prblem it's the name of the variable position. This is invalid but i don't change anything between the two methods. You have an idea? My code: #import "PositionIdentifierViewController.h" #import "WriterXML.h" #import "ParserXML.h" #define timeToScan 0.1 @implementation PositionIdentifierViewController @synthesize accelerometer; @synthesize actualPosition; @synthesize actualX; @synthesize actualY; @synthesize actualZ; -(void)updateTextView:(NSString*)nomePosizione { NSString *string = [NSString stringWithFormat:@"%@",nomePosizione]; textEvent.text = [textEvent.text stringByAppendingString:@"\n"]; textEvent.text = [textEvent.text stringByAppendingString:string]; } -(IBAction)clearTextEvent{ textEvent.text = @""; //with this for my program exit for(int i=0; i<[[sharedController arrayPosition]count]; i++){ NSLog(@"sononelfor"); Position *tempPosition = [[Position alloc]init]; tempPosition = [[sharedController arrayPosition]objectAtIndex:i]; [self updateTextView:(NSString*)[tempPosition name]]; } } -(void)readXml{ if([sharedController readXml]){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Caricamento Posizioni" message:@"Caricamento effettuato con successo" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; [alert release]; NSString *string = [NSString stringWithFormat:@"%d", [[sharedController arrayPosition]count]]; [self updateTextView:(NSString*)string]; //with only this the program is ok for(int i=0; i<[[sharedController arrayPosition]count]; i++){ NSLog(@"sononelfor"); Position *tempPosition = [[Position alloc]init]; tempPosition = [[sharedController arrayPosition]objectAtIndex:i]; [self updateTextView:(NSString*)[tempPosition name]]; } } else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Caricamento Posizioni" message:@"Caricamento non riuscito" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; [alert release]; } } // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; sharedController = [SingletonController sharedSingletonController]; actualPosition = [[Position alloc]init]; self.accelerometer = [UIAccelerometer sharedAccelerometer]; self.accelerometer.updateInterval = timeToScan; self.accelerometer.delegate = self; actualX=0; actualY=0; actualZ=0; [self readXml]; } - (void)dealloc { [super dealloc]; [actualPosition dealloc]; [super dealloc]; } @end #import "SingletonController.h" #import "Position.h" #import "WriterXML.h" #import "ParserXML.h" #define standardSensibility 2 #define timeToScan .1 @implementation SingletonController @synthesize arrayPosition; @synthesize arrayMovement; @synthesize actualPosition; @synthesize actualMove; @synthesize stopThread; +(SingletonController*)sharedSingletonController{ static SingletonController *sharedSingletonController; @synchronized(self) { if(!sharedSingletonController){ sharedSingletonController = [[SingletonController alloc]init]; } } return sharedSingletonController; } -(BOOL)readXml{ ParserXML *newParser = [[ParserXML alloc]init]; if([newParser startParsing:(NSString*)@"filePosizioni.xml"]){ [arrayPosition addObjectsFromArray:[newParser arrayPosition]]; return TRUE; } else return FALSE; } -(id)init{ self = [super init]; if (self != nil) { arrayPosition = [[NSMutableArray alloc]init]; arrayMovement = [[NSMutableArray alloc]init]; actualPosition = [[Position alloc]init]; actualMove = [[Movement alloc]init]; stopThread = FALSE; } return self; } -(void) dealloc { [super dealloc]; } @end

    Read the article

  • iOS bluetooth low energy not detecting peripherals

    - by user3712524
    My app won't detect peripherals. Im using light blue to simulate a bluetooth low energy peripheral and my app just won't sense it. I even installed light blue on two devices to make sure it was generating a peripheral signal properly and it is. Any suggestions? My labels are updating and the NSLog is showing that the scanning is starting. Thanks in advance. #import <UIKit/UIKit.h> #import <CoreBluetooth/CoreBluetooth.h> @interface ViewController : UIViewController @property (weak, nonatomic) IBOutlet UITextField *navDestination; @end #import "ViewController.h" @implementation ViewController - (IBAction)connect:(id)sender { } - (IBAction)navDestination:(id)sender { NSString *destinationText = self.navDestination.text; } - (void)viewDidLoad { } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end #import <UIKit/UIKit.h> #import "ViewController.h" @interface BlueToothViewController : UIViewController @property (strong, nonatomic) CBCentralManager *centralManager; @property (strong, nonatomic) CBPeripheral *discoveredPerepheral; @property (strong, nonatomic) NSMutableData *data; @property (strong, nonatomic) IBOutlet UITextView *textview; @property (weak, nonatomic) IBOutlet UILabel *charLabel; @property (weak, nonatomic) IBOutlet UILabel *isConnected; @property (weak, nonatomic) IBOutlet UILabel *myPeripherals; @property (weak, nonatomic) IBOutlet UILabel *aLabel; - (void)centralManagerDidUpdateState:(CBCentralManager *)central; - (void)centralManger:(CBCentralManager *)central didDiscoverPeripheral: (CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI; -(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error; -(void)cleanup; -(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral; -(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error; -(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error; -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error; -(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error; -(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error; @end @interface BlueToothViewController () @end @implementation BlueToothViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { _centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil options:nil]; _data = [[NSMutableData alloc]init]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [_centralManager stopScan]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)centralManagerDidUpdateState:(CBCentralManager *)central { //you should test all scenarios if (central.state == CBCentralManagerStateUnknown) { self.aLabel.text = @"I dont do anything because my state is unknown."; return; } if (central.state == CBCentralManagerStatePoweredOn) { //scan for devices [_centralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }]; NSLog(@"Scanning Started"); } if (central.state == CBCentralManagerStateResetting) { self.aLabel.text = @"I dont do anything because my state is resetting."; return; } if (central.state == CBCentralManagerStateUnsupported) { self.aLabel.text = @"I dont do anything because my state is unsupported."; return; } if (central.state == CBCentralManagerStateUnauthorized) { self.aLabel.text = @"I dont do anything because my state is unauthorized."; return; } if (central.state == CBCentralManagerStatePoweredOff) { self.aLabel.text = @"I dont do anything because my state is powered off."; return; } } - (void)centralManger:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI { NSLog(@"Discovered %@ at %@", peripheral.name, RSSI); self.myPeripherals.text = [NSString stringWithFormat:@"%@%@",peripheral.name, RSSI]; if (_discoveredPerepheral != peripheral) { //save a copy of the peripheral _discoveredPerepheral = peripheral; //and connect NSLog(@"Connecting to peripheral %@", peripheral); [_centralManager connectPeripheral:peripheral options:nil]; self.aLabel.text = [NSString stringWithFormat:@"%@", peripheral]; } } -(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { NSLog(@"Failed to connect"); [self cleanup]; } -(void)cleanup { //see if we are subscribed to a characteristic on the peripheral if (_discoveredPerepheral.services != nil) { for (CBService *service in _discoveredPerepheral.services) { if (service.characteristics != nil) { for (CBCharacteristic *characteristic in service.characteristics) { if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"508EFF8E-F541-57EF-BD82-B0B4EC504CA9"]]) { if (characteristic.isNotifying) { [_discoveredPerepheral setNotifyValue:NO forCharacteristic:characteristic]; return; } } } } } } [_centralManager cancelPeripheralConnection:_discoveredPerepheral]; } -(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral { NSLog(@"Connected"); [_centralManager stopScan]; NSLog(@"Scanning stopped"); self.isConnected.text = [NSString stringWithFormat:@"Connected"]; [_data setLength:0]; peripheral.delegate = self; [peripheral discoverServices:nil]; } -(void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error { if (error) { [self cleanup]; return; } for (CBService *service in peripheral.services) { [peripheral discoverCharacteristics:nil forService:service]; } //discover other characteristics } -(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error { if (error) { [self cleanup]; return; } for (CBCharacteristic *characteristic in service.characteristics) { [peripheral setNotifyValue:YES forCharacteristic:characteristic]; } } -(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { if (error) { NSLog(@"Error"); return; } NSString *stringFromData = [[NSString alloc]initWithData:characteristic.value encoding:NSUTF8StringEncoding]; self.charLabel.text = [NSString stringWithFormat:@"%@", stringFromData]; //Have we got everything we need? if ([stringFromData isEqualToString:@"EOM"]) { [_textview setText:[[NSString alloc]initWithData:self.data encoding:NSUTF8StringEncoding]]; [peripheral setNotifyValue:NO forCharacteristic:characteristic]; [_centralManager cancelPeripheralConnection:peripheral]; } } -(void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { if ([characteristic.UUID isEqual:nil]) { return; } if (characteristic.isNotifying) { NSLog(@"Notification began on %@", characteristic); } else { [_centralManager cancelPeripheralConnection:peripheral]; } } -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error { _discoveredPerepheral = nil; self.isConnected.text = [NSString stringWithFormat:@"Connecting..."]; [_centralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES}]; } @end

    Read the article

< Previous Page | 5 6 7 8 9