Search Results

Search found 103 results on 5 pages for 'nsmutablestring'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • Appending Strings to NSMutableString

    - by Typeoneerror
    Been looking at this for a bit now and not understanding why this simple bit of code is throwing an error. Shortened for brevity: NSMutableString *output; ... @property (nonatomic, retain) NSMutableString *output; ... @synthesize output; ... // logs "output start" as expected output = [NSMutableString stringWithString:@"output start"]; NSLog(@"%@", output); ... // error happens here [output appendString:@"doing roll for player"]; Can anyone spot my mistake?

    Read the article

  • How do I convert an NSMutableString to NSString when using Frameworks?

    - by BWHazel
    I have written an Objective-C framework which builds some HTML code with NSMutableString which returns the value as an NSString. I have declared an NSString and NSMutableString in the inteface .h file: NSString *_outputLanguage; // Tests language output NSMutableString *outputBuilder; NSString *output; This is a sample from the framework implementation .m code (I cannot print the actual code as it is proprietary): -(NSString*)doThis:(NSString*)aString num:(int)aNumber { if ([outputBuilder length] != 0) { [outputBuilder setString:@""]; } if ([_outputLanguage isEqualToString:@"html"]) { [outputBuilder appendString:@"Some Text..."]; [outputBuilder appendString:aString]; [outputBuilder appendString:[NSString stringWithFormat:@"%d", aNumber]]; } else if ([_outputLanguage isEqualToString:@"xml"]) { [outputBuilder appendString:@"Etc..."]; } else { [outputBuilder appendString:@""]; } output = outputBuilder; return output; } When I wrote a text program, NSLog simply printed out "(null)". The code I wrote there was: TheClass *instance = [[TheClass alloc] init]; NSString *testString = [instance doThis:@"This String" num:20]; NSLog(@"%@", testString); [instance release]; I hope this is enough information!

    Read the article

  • Should I return an NSMutableString in a method that returns NSString

    - by Casey Marshall
    Ok, so I have a method that takes an NSString as input, does an operation on the contents of this string, and returns the processed string. So the declaration is: - (NSString *) processString: (NSString *) str; The question: should I just return the NSMutableString instance that I used as my "work" buffer, or should I create a new NSString around the mutable one, and return that? So should I do this: - (NSString *) processString: (NSString *) str { NSMutableString *work = [NSMutableString stringWithString: str]; // process 'work' return work; } Or this: - (NSString *) processString: (NSString *) str { NSMutableString *work = [NSMutableString stringWithString: str]; // process 'work' return [NSString stringWithString: work]; // or [work stringValue]? } The second one makes another copy of the string I'm returning, unless NSString does smart things like copy-on-modify. But the first one is returning something the caller could, in theory, go and modify later. I don't care if they do that, since the string is theirs. But are there valid reasons for preferring the latter form over the former? And, is either stringWithString or stringValue preferred over the other?

    Read the article

  • NSMutable String "Out of scope"

    - by Garry
    I have two NSMutableString objects defined in my viewController's (a subclass of UITableViewController) .h file: NSMutableString *firstName; NSMutableString *lastName; They are properties: @property (nonatomic, retain) NSMutableString *firstName; @property (nonatomic, retain) NSMutableString *lastName; I synthesis them in the .m file. In my viewDidLoad method - I set them to be blank strings: firstName = [NSMutableString stringWithString:@""]; lastName = [NSMutableString stringWithString:@""]; firstName and lastName can be altered by the user. In my cellForRowAtIndexPath method, I'm trying to display the contents of these strings: cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; but this is causing the app to crash as soon as the view controller is displayed. Using the debugger, it seems that both firstName and lastName are "out of scope" or that they don't exist. I'm new to Xcode but the debugger seems to halt at objc_msgSend. What am I doing wrong?

    Read the article

  • NSMutableString leaks on append or replaceOccurrencesOfString

    - by John
    Hello Folks, I know similar questions have been asked time and time again but I ask that you please bear with me as I cannot seem to find an answer that helps. My application has leaks that are driving me out of my mind. Actually, they are not reported as leaks using Leaks, but my net bytes in ObjectAlloc goes up and up and up and never stops, eventually leading to a crash if it goes on long enough (not very long). The problem occurs with NSMutableStrings. I think there is either something fundamental I don't understand about them, or I am facing another problem that I am having difficulty tracking down but keeps hiding behind the NSMutableStrings. Specifically, I am noticing that whenever I append to or perform a replace on a NSMutableString, ObjectAlloc reports what appear to be mismatches in malloc/frees behind the scene when resizing the NSMutableString. I'm sorry to say this is the second time I'm facing this problem - the first time I messed around for hours and hours and finally the problem went away (magic!) but I don't really know why. When I look at the code below (and believe me, I've stared at it for hours) I cannot see the problem. I look at the code and think to myself that I should be fine because I'm releasing the only object for which I am responsible (aString) and that NSMutableString should be taking care of cleaning up after any resizing it does. In the second example, just so you know in case it helps, the string being passed in comes from an ASIHTTPRequest object (it's the responseString) and I don't do anything at all with it. It's being called simply like so ([self DoStuff2:[request responseString]]) and I don't free the request myself either (I'm using a ASINetworkQueue and I assume that the requests are destroyed for me (I tried and caused errors because the request was already being release somewhere else). Also, I know it shouldn't do anything, but I even tried wrapping the code in autorelease pools, which of course did nothing. I should mention that this code is being run inside of an NSOperation. I thought that perhaps I am experiencing problems because NSOperations should create an autorelease pool for themselves, but I've tried that to no avail. Not related to NSMutableString, but I find I also have similar problems using the NSString componentsSeparatedByString method. Sometimes the memory used by the array that gets the separated components is never released. Hmmm...strings in general seem to be somewhat problematic for me it seems. I would appreciate ANY help anyone can provide. If you require more info, I'll be glad to add it. I do promise you that I've struggled with this (and other problems) for weeks and every problem I encounter I research hard and long until I find a solution - this is not an idle request, but a true cry for help! I've written so much code and now I'm trying to seal some small leaks etc and I notice this problem. Honestly, I cannot believe how memory management in Objective C can stump me so at times...I've read Apple's memory mgmt docs many times and I thought I thoroughly understood it and I try to be diligent about releasing objects I own, but sometimes I find myself wondering if I truly understand...I would like to put this to bed once and make sure I understand all this fully - to have this sort of question/problem after writing thousands of lines of code is more than a little scary/embarrassing/annoying. So again, if anybody has any insight, I'd be grateful. Thanks for your time and efforts. -(void)DoStuff { NSString *aString [ [[NSString alloc] initWithFormat:@"text %@ more text", self.strVariable]; [self.someMutableStringVar replaceOccurrencesOfString:@"replace" withString:aString options:NSCaseInsensitiveSearch range:NSMakeRange(0, [self.someMutableStringVar length])]; [aString release]; } -(void)DoStuff2:(NSString *)aString { [self.someMutableStringVar appendString:aString]; }

    Read the article

  • Generating a list of Strings in Obj C

    - by eco_bach
    Hi It seems that Objective C jumps thru hoops to make seemingly simple tasks extremely difficult. I simply need to create a sequence of strings, image1.jpg, image2.jpg, etc etc ie in a loop var imgString:String='image'+i+'.jpg; I assume a best practice is to use a NSMutableString with appendString method? What am I doing wrong?? NSMutableString *imgString; for(int i=1;i<=NUMIMAGES;i++){ imgString.appendString(@"image"+i+@".jpg"); } I get the following error error: request for member 'appendString' in something not a structure or union

    Read the article

  • Concatenating Strings in Obj C

    - by eco_bach
    Hi It seems that Objective C jumps thru hoops to make seemingly simple tasks extremely difficult. I simply need to create a sequence of strings, image1.jpg, image2.jpg, etc etc ie in a loop var imgString:String='image'+i+'.jpg; I assume a best practice is to use a NSMutableString with appendString method? What am I doing wrong?? NSMutableString *imgString; for(int i=1;i<=NUMIMAGES;i++){ imgString.appendString(@"image"+i+@".jpg"); } I get the following error error: request for member 'appendString' in something not a structure or union

    Read the article

  • How do I send the mutable string to the NSTextField properly?

    - by Merle
    So I have all this code that I have debugged and it seems to be fine. I made a mutable string and for some reason I can not get it to be displayed on my label. the debugger says "2010-04-22 22:50:26.126 Fibonacci[24836:10b] * -[NSTextField setString:]: unrecognized selector sent to instance 0x130150" What is wrong with this? When I just send the string to NSLog, it comes out fine. here's all my code, any help would be appreciated. "elementNum" is a comboBox and "display" is a Label. Thanks #import "Controller.h" @implementation Controller - (IBAction)computeNumber:(id)sender { int x = 1; int y = 1; NSMutableString *numbers = [[NSMutableString alloc] init]; [numbers setString:@"1, 1,"]; int num = [[elementNum objectValueOfSelectedItem]intValue]; int count = 1; while (count<=num) { int z = y; y+=x; x=z; [numbers appendString:[NSString stringWithFormat:@" %d,", y]]; count++; } [display setString:numbers]; NSLog(numbers); } @end `

    Read the article

  • nsdata to nsstring to nsdata

    - by Jayshree
    Hello everybody. I am calling the webservices. The web service returns data in xml format. Now the problem is the xml data is not being received in proper format. In place of "<", "" it returns in html format like-(<) and (>) . So i assigned the xmldata to a NsMutableString and replaced the escape characters so that the format of xml data is proper. Then i reassigned the NSMutableString to NSData so that i can parse the tags. but the problem is the xmlparser stops right where the xml data is. Where i replaced the tags. it doesnt go further. can anybody make me understand what is going on???? This is the xml response from webservice that i called. <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:GetCustomerInfoResponse xmlns:ns1="http://aa.somewebservice.com/phpwebservice"> <return xsi:type="xsd:string"> &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;customer&gt;&lt;id&gt;1&lt;/id&gt;&lt;customername&gt;Hitesh&lt;/customername&gt;&lt;phonenumber&gt;98989898&lt;/phonenumber&gt;&lt;/customer&gt; </return> </ns1:GetCustomerInfoResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> And this is after i replaced the tags. <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:GetCustomerInfoResponse xmlns:ns1="http://a.somewebservice.com/phpwebservice"> <return xsi:type="xsd:string"> <?xml version="1.0" encoding="utf-8"?> <customer><id>1</id><customername>Hitesh</customername><phonenumber>98989898</phonenumber></customer> </return> </ns1:GetCustomerInfoResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope> Now the problem is while parsing the parser only goes upto return tag. And then it is stuck there. It doesnt go any further. So wat do i do? anybody care to help me?

    Read the article

  • function to get the file name of an URL

    - by user262325
    Hello everyone I have some source code to get the file name of an url for example: http://www.google.com/a.pdf I hope to get a.pdf because the way to join 2 NSStrings I can get is 'appendString' which only for adding a string at right side, so I planned to check each char one by one from the right side of string 'http://www.google.com/a.pdf', when it reach at the char '/', stop the checking, return string fdp.a , after that I change fdp.a to a.pdf source codes are below -(NSMutableString *) getSubStringAfterH : originalString:(NSString *)s0 { NSInteger i,l; l=[s0 length]; NSMutableString *h=[[NSMutableString alloc] init]; NSMutableString *ttt=[[NSMutableString alloc] init ]; for(i=l-1;i>=0;i--) //check each char one by one from the right side of string 'http://www.google.com/a.pdf', when it reach at the char '/', stop { ttt=[s0 substringWithRange:NSMakeRange(i, 1)]; if([ttt isEqualToString:@"/"]) { break; } else { [h appendString:ttt]; } } [ttt release]; //below are to change the sequence of char in h // txt.edcba -> abcde.txt NSMutableString *h1=[[[NSMutableString alloc] initWithFormat:@""] autorelease]; for (i=[h length]-1;i>=0;i--) { NSMutableString *t1=[[NSMutableString alloc] init ]; t1=[h substringWithRange:NSMakeRange(i, 1)]; [h1 appendString:t1]; [t1 release]; } [h release]; return h1; } h1 can reuturn the coorect string a.pdf, but if it returns to the codes where it was called, after a while system reports 'double free * set a breakpoint in malloc_error_break to debug' I checked a long time and foudn that if I removed the code ttt=[s0 substringWithRange:NSMakeRange(i, 1)]; everything will be Ok (of course getSubStringAfterH can not returns the corrent result I expected.), no error reported. I try to fix the bug a few hours, but still no clue. Welcome any comment Thanks interdev

    Read the article

  • Release variable and assigning it again

    - by David Gonrab
    What is the preferred and/or correct way to release an NSMutableString (or any other class for that matter) instance and assign a new instance to the same variable in Objective-C on the iPhone? Currently I'm using [current release]; current = [NSMutableString new]; but I understand that the following works, too. NSMutableString *new = [NSMutableString new]; [current release]; current = [new retain]; [new release]; The variable current is declared in the interface definition of my class and gets released in dealloc.

    Read the article

  • Using NSXMLParser to parse Vimeo XML on iPhone.

    - by Sonny Fazio
    Hello, I'm working on an iPhone app that will use Vimeo Simple API to give me a listing our videos by a certain user, in a convenient TableView format. I'm new to Parsing XML and have tried TouchXML, TinyXML, and now NSXMLParser with no luck. Most tutorials on parsing XML are for a blog, and not for an API XML sheet. I've tried modifying the blog parsers to search for the specific tags, but it doesn't seem to work. Right now I'm working with NSXMLParser and it seems to correctly find the value of an XML tag, but when it goes to append it to a NSMutableString, it writes a whole bunch of nulls in between it. I'm using a tutorial from theappleblog and modifying it to work with Vimeo API - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if ([currentElement isEqualToString:@"video_title"]) { NSLog(@"String: %@",string); [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"video_url"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"video_description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"date"]) { [currentDate appendString:string]; } Here is the nulls it writes: http://grab.by/grabs/92d9cfc2df4fac3fe6579493b1a8e89f.png Then when it finishes, it has to add the NSMutableStrings into a NSMutableDictionary - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ NSLog(@"Title: %@",currentTitle); if ([elementName isEqualToString:@"item"]) {// save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"video_title"]; NSLog(@"Current Title%@", currentTitle); [item setObject:currentLink forKey:@"video_url"]; [item setObject:currentSummary forKey:@"video_description"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } I would really appreciate it if someone has any advance

    Read the article

  • UITableViewCell selected subview ghosts

    - by Jonathan Cohen
    Hi all, I'm learning about the iPhone SDK and have an interesting exception with UITableViewCell subview management when a finger is pressed on some rows. The table is used to assign sounds to hand gestures -- swiping the phone in one of 3 directions triggers the sound to play. Selecting a row displays an action sheet with 4 options for sound assignment: left, down, right, and cancel. Sounds can be mapped to one, two, or three directions so any cell can have one of seven states: left, down, right, left and down, left and right, down and right, or left down and right. If a row is mapped to any of these seven states, a corresponding arrow or arrows are displayed within the bounds of the row as a subview. Arrows come and go as they should in a given screen and when scrolling around. However, after scrolling to a new batch of rows, only when I press my finger down on some (but not all) rows, does an arrow magically appear in the selected state background. When I lift my finger off the row, and the action sheet appears, the arrow disappears. After pressing any of the four buttons, I can't replicate this anymore. But it's really disorienting and confusing to see this arrow flash on screen because the selected row isn't assigned to anything. What haven't I thought to look into here? All my table code is pasted below and this is a screencast of the problem: http://www.screencast.com/users/JonathanGCohen/folders/Jing/media/d483fe31-05b5-4c24-ab4d-70de4ff3a0bf Am I managing my subviews wrong or is there a selected state property I'm missing? Something else? Should I have included any more information in this post to make things clearer? Thank you!! #pragma mark - #pragma mark Table - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ([categories count] > 0) ? [categories count] : 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([categories count] == 0) return 0; NSMutableString *key = [categories objectAtIndex:section]; NSMutableArray *nameSection = [categoriesSounds objectForKey:key]; return [nameSection count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *nameSection = [categoriesSounds objectForKey:key]; static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SectionsTableIdentifier]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; NSString *soundOfType = [[sound objectAtIndex: row] objectAtIndex: 1]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease]; } cell.textLabel.text = [[nameSection objectAtIndex:row] objectAtIndex: 0]; NSUInteger soundSection = [[[sound objectAtIndex: row] objectAtIndex: 2] integerValue]; NSUInteger soundRow = [[[sound objectAtIndex: row] objectAtIndex: 3] integerValue]; NSUInteger leftRow = [leftOldIndexPath row]; NSUInteger leftSection = [leftOldIndexPath section]; if (soundRow == leftRow && soundSection == leftSection && leftOldIndexPath !=nil){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeft]; selectedSoundLeft.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeft]; } NSUInteger downRow = [downOldIndexPath row]; NSUInteger downSection = [downOldIndexPath section]; if (soundRow == downRow && soundSection == downSection && downOldIndexPath !=nil){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundDown]; selectedSoundDown.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundDown]; } NSUInteger rightRow = [rightOldIndexPath row]; NSUInteger rightSection = [rightOldIndexPath section]; if (soundRow == rightRow && soundSection == rightSection && rightOldIndexPath !=nil){ [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundRight]; selectedSoundRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundRight]; } // combos if (soundRow == leftRow && soundRow == downRow && soundSection == leftSection && soundSection == downSection){ [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndDown]; selectedSoundLeftAndDown.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndDown]; } if (soundRow == leftRow && soundRow == rightRow && soundSection == leftSection && soundSection == rightSection){ [selectedSoundLeft removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndRight]; selectedSoundLeftAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndRight]; } if (soundRow == downRow && soundRow == rightRow && soundSection == downSection && soundSection == rightSection){ [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundDownAndRight]; selectedSoundDownAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundDownAndRight]; } if (soundRow == leftRow && soundRow == downRow && soundRow == rightRow && soundSection == leftSection && soundSection == downSection && soundSection == rightSection){ [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [cell.contentView addSubview: selectedSoundLeftAndDownAndRight]; selectedSoundLeftAndDownAndRight.frame = CGRectMake(200,8,30,30); } else { [cell.contentView sendSubviewToBack: selectedSoundLeftAndDownAndRight]; } [indexPath retain]; return cell; } - (NSMutableString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if ([categories count] == 0) return nil; NSMutableString *key = [categories objectAtIndex:section]; if (key == UITableViewIndexSearch) return nil; return key; } - (NSMutableArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { if (isSearching) return nil; return categories; } - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { [table reloadData]; [selectedSoundLeft removeFromSuperview]; [selectedSoundDown removeFromSuperview]; [selectedSoundRight removeFromSuperview]; [selectedSoundLeftAndDown removeFromSuperview]; [selectedSoundLeftAndRight removeFromSuperview]; [selectedSoundDownAndRight removeFromSuperview]; [selectedSoundLeftAndDownAndRight removeFromSuperview]; [search resignFirstResponder]; if (isSearching == YES && [search.text length] != 0 ){ searched = YES; } search.text = @""; isSearching = NO; [tableView reloadData]; [indexPath retain]; [indexPath retain]; return indexPath; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [table reloadData]; selectedIndexPath = indexPath; [table reloadData]; NSInteger section = [indexPath section]; NSInteger row = [indexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; [indexPath retain]; [indexPath retain]; NSMutableString *title = [NSMutableString stringWithString: @"Assign Gesture for "]; NSMutableString *soundFeedback = [NSMutableString stringWithString: (@"%@", soundName)]; [title appendString: soundFeedback]; UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:(@"%@", title) delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle: nil otherButtonTitles:@"Left",@"Down",@"Right",nil]; action.actionSheetStyle = UIActionSheetStyleDefault; [action showInView:self.view]; [action release]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger section = [selectedIndexPath section]; NSInteger row = [selectedIndexPath row]; NSString *key = [categories objectAtIndex:section]; NSArray *sound = [categoriesSounds objectForKey:key]; NSString *soundName = [[sound objectAtIndex: row] objectAtIndex: 0]; NSString *soundOfType = [[sound objectAtIndex: row] objectAtIndex: 1]; NSUInteger soundSection = [[[sound objectAtIndex: row] objectAtIndex: 2] integerValue]; NSUInteger soundRow = [[[sound objectAtIndex: row] objectAtIndex: 3] integerValue]; NSLog(@"sound row is %i", soundRow); NSLog(@"sound section is row is %i", soundSection); typedef enum { kLeftButton = 0, kDownButton, kRightButton, kCancelButton } gesture; switch (buttonIndex) { //Left case kLeftButton: showLeft.text = soundName; left = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:left], &soundNegZ); AudioServicesPlaySystemSound (soundNegZ); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; leftIndexSection = [NSNumber numberWithInteger:section]; leftIndexRow = [NSNumber numberWithInteger:row]; NSInteger leftSection = [leftIndexSection integerValue]; NSInteger leftRow = [leftIndexRow integerValue]; NSString *leftKey = [categories objectAtIndex: leftSection]; NSArray *leftSound = [categoriesSounds objectForKey:leftKey]; NSInteger leftSoundSection = [[[leftSound objectAtIndex: leftRow] objectAtIndex: 2] integerValue]; NSInteger leftSoundRow = [[[leftSound objectAtIndex: leftRow] objectAtIndex: 3] integerValue]; leftOldIndexPath = [NSIndexPath indexPathForRow:leftSoundRow inSection:leftSoundSection]; break; //Down case kDownButton: showDown.text = soundName; down = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:down], &soundNegX); AudioServicesPlaySystemSound (soundNegX); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; downIndexSection = [NSNumber numberWithInteger:section]; downIndexRow = [NSNumber numberWithInteger:row]; NSInteger downSection = [downIndexSection integerValue]; NSInteger downRow = [downIndexRow integerValue]; NSString *downKey = [categories objectAtIndex: downSection]; NSArray *downSound = [categoriesSounds objectForKey:downKey]; NSInteger downSoundSection = [[[downSound objectAtIndex: downRow] objectAtIndex: 2] integerValue]; NSInteger downSoundRow = [[[downSound objectAtIndex: downRow] objectAtIndex: 3] integerValue]; downOldIndexPath = [NSIndexPath indexPathForRow:downSoundRow inSection:downSoundSection]; break; //Right case kRightButton: showRight.text = soundName; right = [[NSBundle mainBundle] pathForResource:(@"%@", soundName) ofType:(@"%@", soundOfType)]; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:right], &soundPosX); AudioServicesPlaySystemSound (soundPosX); [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; rightIndexSection = [NSNumber numberWithInteger:section]; rightIndexRow = [NSNumber numberWithInteger:row]; NSInteger rightSection = [rightIndexSection integerValue]; NSInteger rightRow = [rightIndexRow integerValue]; NSString *rightKey = [categories objectAtIndex: rightSection]; NSArray *rightSound = [categoriesSounds objectForKey:rightKey]; NSInteger rightSoundSection = [[[rightSound objectAtIndex: rightRow] objectAtIndex: 2] integerValue]; NSInteger rightSoundRow = [[[rightSound objectAtIndex: rightRow] objectAtIndex: 3] integerValue]; rightOldIndexPath = [NSIndexPath indexPathForRow:rightSoundRow inSection:rightSoundSection]; break; case kCancelButton: [table deselectRowAtIndexPath:selectedIndexPath animated:YES]; break; default: break; } UITableViewCell *viewCell = [table cellForRowAtIndexPath: selectedIndexPath]; NSArray *subviews = viewCell.subviews; for (UIView *cellView in subviews){ cellView.alpha = 1; } [table reloadData]; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSMutableString *)title atIndex:(NSInteger)index { NSMutableString *category = [categories objectAtIndex:index]; if (category == UITableViewIndexSearch) { [tableView setContentOffset:CGPointZero animated:NO]; return NSNotFound; } else return index; }

    Read the article

  • String formatting in cocoa

    - by lostInTransit
    Hi I am trying to send some text in an email from my cocoa app (by using Mail.app). Initially I tried using HTML to send properly formatted text. But the mailto: URL does not support html tags (even after setting headers) So I decided to use formatted string (left-aligning of string) This is what I have in my mailto: link's body argument NSMutableString *emailBody = [NSMutableString stringWithFormat:@"|%-35s", [@"Name" UTF8String]]; [emailBody appendFormat:@"|%-18s", [@"Number" UTF8String]]; [emailBody appendString:@"|Notes\n"]; [emailBody appendString:@"----------------------------------------------------------------------------------------------------"]; for(int i = 0; i < [items count]; i++){ NSDictionary *props = [items objectAtIndex:i]; NSMutableString *emailData = [NSMutableString stringWithFormat:@"|%-35s", [[props valueForKey:@"name"] UTF8String]]; [emailData appendFormat:@"|$ %-16s", [[props valueForKey:@"number"] UTF8String]]; [emailData appendString:[props valueForKey:@"notes"]]; [emailBody appendString:@"\n"]; [emailBody appendString:emailData]; } This does give me padded text but they all don't necessarily take up the same space (for instance if there is an O in the text, it takes up more space than others and ruins the formatting) Is there another sure-shot way to format text using just NSString? Thanks

    Read the article

  • xml parsing using nsxmlParser in iphone

    - by filthynight
    hi all, I have a problem in parsing xml from google api, the api xml looks like this ....... Now the problem is that first of all, the tags are different, like first parent tag name is "abc" and second parent tag is "efg", further more the inner tags are different as well. i have modified code got from web that it parses another url, but in this case since the tags keeps on changing it does not work. the url = "http://www.google.com/ig/api?weather=anaheim,ca" Source Code (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); if (currentElement) { [currentElement release]; currentElement = nil; } currentElement = [elementName copy]; NSString *thisOwner = [attributeDict objectForKey:@"data"]; NSLog(@"element Name-------: %@", thisOwner); if ([elementName isEqualToString:@"forecast_information"]) //|| [elementName isEqualToString:@"current_conditions"] || [elementName isEqualToString:@"forecast_conditions"]) { // clear out our story item caches... //NSString *nm = [[attributeDict objectForKey:@"city"] stringValue]; //NSLog(@"value...%@",nm); item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; [item setObject:currentLink forKey:@"postal_code"]; [item setObject:currentSummary forKey:@"current_date_time"]; [item setObject:currentDate forKey:@"unit_system"]; NSLog(@"adding story: %@", currentTitle); [stories addObject:[item copy]]; } } I have another function didEndElement where the values are assigned in the array, but i could not figure out how to assign values of an attribute. Can somebody please help me in this regards Thanks!

    Read the article

  • Using NSXMLParser with CDATA

    - by Robb
    I'm parsing an RSS feed with NSXMLParser and it's working fine for the title and other strings but one of the elements is an image thats like <!CDATA <a href="http:image..etc> How do I add that as my cell image in my table view? Would I define that as an image type? This is what i'm using to do my parsing: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [ [NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ //NSLog(@"ended element: %@", elementName); if ([elementName isEqualToString:@"item"]) { // save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"title"]; [item setObject:currentLink forKey:@"link"]; [item setObject:currentSummary forKey:@"description"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([currentElement isEqualToString:@"title"]) { [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"link"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"pubDate"]) { [currentDate appendString:string]; } }

    Read the article

  • Why Won't this http post request work?

    - by dubbeat
    Hi, I'm wondering why this http post request won't work for my iphone app. I know for a fact that the url is correct and that the variables I'm sending are correct but for some reason the request is not being recieved by the aspx page. NSMutableString *httpBodyString; NSURL *url; NSMutableString *urlString; httpBodyString=[NSMutableString stringWithFormat:@"%@%@%@%@%@",@"?g=",promoValueObject.country,@"&c=",promoData.artistid,@"&d=iphone"]; urlString=[[NSMutableString alloc] initWithString:@"http://www.mysite.com/stats_promo.aspx"]; url=[[NSURL alloc] initWithString:urlString]; [urlString release]; NSMutableURLRequest *urlRequest=[NSMutableURLRequest requestWithURL:url]; [url release]; [urlRequest setHTTPMethod:@"POST"]; [urlRequest setHTTPBody:[httpBodyString dataUsingEncoding:NSISOLatin1StringEncoding]]; //[httpBodyString release]; NSURLConnection *connectionResponse = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; if (!connectionResponse) { NSLog(@"Failed to submit request"); } else { NSLog(@"--------- Request submitted ---------"); NSLog(@"connection: %@ method: %@, encoded body: %@, body: %a", connectionResponse, [urlRequest HTTPMethod], [urlRequest HTTPBody], httpBodyString); }

    Read the article

  • Obj-msg-send error in numberOfSectionsInTableView

    - by mukeshpawar
    import "AddBillerCategoryViewController.h" import "Globals.h" import "AddBillerViewController.h" import "AddBillerListViewController.h" import"KlinnkAppDelegate.h" @implementation AddBillerCategoryViewController @synthesize REASON, RESPVAR, currentAttribute,tbldata,strOptions; // This recipe adds a title for each section //Initialize the table view controller with the grouped style (AddBillerCategoryViewController *) init { if (self = [super initWithStyle:UITableViewStyleGrouped]);// self.title = @"Crayon Colors"; return self; } -(void)showBack { [[self navigationController] pushViewController:[[AddBillerViewController alloc] init] animated:YES]; } (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if ([viewController isKindOfClass:[AddBillerCategoryViewController class]]) { AddBillerCategoryViewController *controller = (AddBillerCategoryViewController *)viewController; [controller.tbldata reloadData]; } } (void)viewDidLoad { appDelegate = (KlinnkAppDelegate *)[[UIApplication sharedApplication] delegate]; appDelegate.catListArray.count; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; //self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] // initWithTitle:@"Back" // style:UIBarButtonItemStylePlain // target:self // action:@selector(showBack)] autorelease]; if(gotOK == 0) { //self.navigationItem.leftBarButtonItem.enabled = FALSE; dt = [[DateTime alloc] init]; strChannelID = @"IGLOO|MOBILE"; strDateTime = [dt findDateTime]; strTemp = [dt findSessionTime]; strSessionID = [appDelegate.KMobile stringByAppendingString:strTemp]; strResponseURL = @"http://115.113.110.139/Test/CbbpServerRequestHandler"; strResponseVar = @"serverResponseXML"; strRequestType = @"GETCATEGORY"; NSLog(@"Current Session id - %@", strSessionID); //conn = [[NSURLConnection alloc] init]; receivedData = [[NSMutableData data] retain]; //.................... currentAttribute = [[NSMutableString alloc] init]; // create XMl xmlData = [[NSData alloc] init]; xmlData = [self createXML]; // XMl has been created now convert it in to string xmlString = [[NSString alloc] initWithData:xmlData encoding:NSASCIIStringEncoding]; // Ataching other infromatin to he xml parameterString = [[NSString alloc] initWithString:@"mobileRequestXML="]; requestString = [[NSString alloc] init]; requestString = [parameterString stringByAppendingString:xmlString]; // give space betn two element. requestString = [requestString stringByReplacingOccurrencesOfString:@"<" withString:@" <"]; // Initalizing other parameters postData = [requestString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; postLength = [NSString stringWithFormat:@"%d",[postData length]]; firstRequest = [[[NSMutableURLRequest alloc] init] autorelease]; REASON = [[NSMutableString alloc] init]; RESPVAR = [[NSMutableString alloc] init]; NSLog(@"\n \n Sending for 1st time........\n"); [self sendRequest]; NSLog(@"\n \n Sending for 2nd time........\n"); [self sendRequest]; NSLog(@"\n \n both request send........\n \n "); } //[tbldata reloadData]; [self retain]; [super viewDidLoad]; } -(void)sendRequest { finished = FALSE; NSLog(@"\n Sending Request \n\n %@", requestString); conn = [[NSURLConnection alloc] init]; if(gotOK == 0) [firstRequest setURL:[NSURL URLWithString:@"http://115.113.110.139/Test/CbbpMobileRequestHandler"]]; if(gotOK == 1) { [firstRequest setURL:[NSURL URLWithString:@"http://115.113.110.139//secure"]]; gotOK = 2; } [firstRequest setHTTPMethod:@"POST"]; [firstRequest setValue:postLength forHTTPHeaderField:@"Content-Length"]; [firstRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [firstRequest setHTTPBody:postData]; conn = [conn initWithRequest:firstRequest delegate:self startImmediately:YES]; [conn start]; while(!finished) { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } if (conn) { //receivedData = [[NSMutableData data] retain]; NSLog(@"\n\n Received %d bytes of data",[receivedData length]); } else { NSLog(@"\n Not responding"); } } (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@" \n Send didReciveResponse"); [receivedData setLength:0]; } (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@" \n Send didReciveData"); [receivedData appendData:data]; } (void)connectionDidFinishLoading:(NSURLConnection *)connection { finished = TRUE; NSLog(@" \n Send didFinishLaunching"); // do something with the data // receivedData is declared as a method instance elsewhere NSLog(@"\n\n Succeeded! DIDFINISH Received %d bytes of data\n\n ",[receivedData length]); NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]; NSLog(aStr); //[conn release]; if([aStr isEqualToString:@"OK"]) gotOK = 1; NSLog(@" Value of gotOK - %d", gotOK); if(gotOK == 2) { responseData = [aStr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; parser = [[NSXMLParser alloc] initWithData:responseData]; [parser setDelegate:self]; NSLog(@"\n start parsing"); [parser parse]; NSLog(@"\n PArsing over"); NSLog(@"\n check U / S and the RESVAR is - %@",RESPVAR); NSRange textRange; textRange =[aStr rangeOfString:@"<"]; if(textRange.location != NSNotFound) { if([RESPVAR isEqualToString:@"U"]) { self.navigationItem.rightBarButtonItem.enabled = TRUE; self.navigationItem.leftBarButtonItem.enabled = TRUE; NSLog(@" \n U......."); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:REASON delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; [alert release]; } if([RESPVAR isEqualToString:@"S"]) { NSLog(@"\n S........"); [[self navigationController] pushViewController:[[AddBillerCategoryViewController alloc] init] animated:YES]; //[self viewDidLoad]; //[tbldata reloadData]; } } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Connection Problem" message:@"Enable to process your request at this time. Please try again." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; [alert release]; //self.navigationItem.leftBarButtonItem.enabled = TRUE; } } NSLog(@"\n Last line of connectionDidFinish "); //[tableView reloadData]; } -(NSData *)createXML { NSString *strXmlNode = @" channel alliaceid session reqtype responseurl responsevar "; NSString *tempchannel = [strXmlNode stringByReplacingOccurrencesOfString:@"channel" withString:strChannelID options:NSBackwardsSearch range:NSMakeRange(0, [strXmlNode length])]; NSString *tempalliance = [tempchannel stringByReplacingOccurrencesOfString:@"alliaceid" withString:@"WALLET365" options:NSBackwardsSearch range:NSMakeRange(0, [tempchannel length])]; NSString *tempsession = [tempalliance stringByReplacingOccurrencesOfString:@"session" withString:strSessionID options:NSBackwardsSearch range:NSMakeRange(0, [tempalliance length])]; NSString *tempreqtype = [tempsession stringByReplacingOccurrencesOfString:@"reqtype" withString:strRequestType options:NSBackwardsSearch range:NSMakeRange(0,[tempsession length])]; NSString *tempresponseurl = [tempreqtype stringByReplacingOccurrencesOfString:@"responseurl" withString:strResponseURL options:NSBackwardsSearch range:NSMakeRange(0, [tempreqtype length])]; NSString *tempresponsevar = [tempresponseurl stringByReplacingOccurrencesOfString:@"responsevar" withString:strResponseVar options:NSBackwardsSearch range:NSMakeRange(0,[tempresponseurl length])]; NSData *data= [[NSString stringWithString:tempresponsevar] dataUsingEncoding:NSUTF8StringEncoding]; return data; } (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"RESPVAL"]) currentAttribute = [NSMutableString string]; if([elementName isEqualToString:@"REASON"]) currentAttribute = [NSMutableString string]; if([elementName isEqualToString:@"COUNT"]) currentAttribute = [NSMutableString string]; if([elementName isEqualToString:@"CATNAME"]) currentAttribute = [NSMutableString string]; } (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName { if([elementName isEqualToString:@"RESPVAL"]) { [RESPVAR setString:currentAttribute]; //NSLog(@"\n Response VAR - %@", RESPVAR); } if([elementName isEqualToString:@"REASON"]) { [REASON setString:currentAttribute]; //NSLog(@"\n Reason - %@", REASON); } if([elementName isEqualToString:@"COUNT"]) { NSString *temp1 = [[NSString alloc] init]; temp1 = [temp1 stringByAppendingString:currentAttribute]; catCount = [temp1 intValue]; [temp1 release]; //NSLog(@"\n Cat Count - %d", catCount); } if([elementName isEqualToString:@"CATNAME"]) { [appDelegate.catListArray addObject:[NSString stringWithFormat:currentAttribute]]; //NSLog(@"%@", appDelegate.catListArray); } } (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { if(self.currentAttribute) [self.currentAttribute setString:string]; } /* (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } */ /* (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } */ /* (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } */ /* (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } */ /* // Override to allow orientations other than the default portrait orientation. (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview // Release anything that's not essential, such as cached data } pragma mark Table view methods -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { KlinnkAppDelegate *appDelegated = (KlinnkAppDelegate *)[[UIApplication sharedApplication] delegate]; return appDelegated.catListArray.count; } // Customize the appearance of table view cells. (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; } // Set up the cell... AddBillerCategoryViewController *mbvc = (AddBillerCategoryViewController *)[appDelegate.catListArray objectAtIndex:indexPath.row]; [cell setText:mbvc.strOptions]; return cell; } (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; // [self.navigationController pushViewController:anotherViewController]; // [anotherViewController release]; gotOK = 0; int j = indexPath.row; appDelegate.catName = [[NSString alloc] init]; appDelegate.catName = [appDelegate.catName stringByAppendingString:[appDelegate.catListArray objectAtIndex:j]]; [[self navigationController] pushViewController:[[AddBillerListViewController alloc] init] animated:YES]; } /* // Override to support conditional editing of the table view. (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return YES; } */ /* // Override to support editing the table view. (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view } } */ /* // Override to support rearranging the table view. (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { } */ /* // Override to support conditional rearranging of the table view. (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the item to be re-orderable. return YES; } */ (void)dealloc { [REASON release]; [RESPVAR release]; [currentAttribute release]; [tbldata release]; [super dealloc]; } @end In the Above code .. numberOfSectionsInTableView ,i get error of obj-msg-send i have intialize the array catlist and even not released it anywhere still why i am getting this error please help me i am badly stuck' thanks in advacnce

    Read the article

  • iPhone GUI for real-time log message display

    - by zer0stimulus
    My goal is to have a screen on my GUI dedicated to logging real-time messages generated by my internal components. A certain limit will be set on the log messages so that older messages are pruned. I'm thinking about implementing using a UITextView with a NSMutableString to store the output. I would have to perform manual pruning somehow on the NSMutableString object. Is a better way to implement this?

    Read the article

  • iPhone RSS thumbnail

    I have a simple RSS reader. Stories are downloaded, put into a UITableView, and when you click it, each story loads in a UIWebView. It works great. Now though, I'd like to incorporate an image on the left side (like you'd see in the YouTube app). However, since my app pulls from an RSS feed, I can't simply specify image X to appear in row X because row X will be row Y tomorrow, and things will get out of order, you know? I am currently pulling from a YouTube RSS feed, and can get the video title, description, publication date, but I'm stuck as to how to pull the little thumbnail besides each entry in the feed. As you can probably tell, I'm a coding newbie (this being my first application other than a Hello World app) and I'm getting so frustrated by my own lack of knowledge. Thanks! BTW, here's some sample code: - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); if (currentElement) { [currentElement release]; currentElement = nil; } currentElement = [elementName copy]; if ([elementName isEqualToString:@"item"]) { // clear out our story item caches... item = [[NSMutableDictionary alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentDate = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentLink = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ //NSLog(@"ended element: %@", elementName); if ([elementName isEqualToString:@"item"]) { // save values to an item, then store that item into the array... [item setObject:currentTitle forKey:@"title"]; [item setObject:currentLink forKey:@"link"]; [item setObject:currentSummary forKey:@"summary"]; [item setObject:currentDate forKey:@"date"]; [stories addObject:[item copy]]; NSLog(@"adding story: %@", currentTitle); } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([currentElement isEqualToString:@"title"]) { [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"link"]) { [currentLink appendString:string]; } else if ([currentElement isEqualToString:@"description"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"pubDate"]) { [currentDate appendString:string]; } }

    Read the article

  • Convert NSData into Hex NSString

    - by Dawson
    With reference to the following question: Convert NSData into HEX NSSString I have solved the problem using the solution provided by Erik Aigner which is: NSData *data = ...; NSUInteger capacity = [data length] * 2; NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:capacity]; const unsigned char *dataBuffer = [data bytes]; NSInteger i; for (i=0; i<[data length]; ++i) { [stringBuffer appendFormat:@"%02X", (NSUInteger)dataBuffer[i]]; } However, there is one small problem in that if there are extra zeros at the back, the string value would be different. For eg. if the hexa data is of a string @"3700000000000000", when converted using a scanner to integer: unsigned result = 0; NSScanner *scanner = [NSScanner scannerWithString:stringBuffer]; [scanner scanHexInt:&result]; NSLog(@"INTEGER: %u",result); The result would be 4294967295, which is incorrect. Shouldn't it be 55 as only the hexa 37 is taken? So how do I get rid of the zeros? EDIT: (In response to CRD) Hi, thanks for clarifying my doubts. So what you're doing is to actually read the 64-bit integer directly from a byte pointer right? However I have another question. How do you actually cast NSData to a byte pointer? To make it easier for you to understand, I'll explain what I did originally. Firstly, what I did was to display the data of the file which I have (data is in hexadecimal) NSData *file = [NSData dataWithContentsOfFile:@"file path here"]; NSLog(@"Patch File: %@",file); Output: Next, what I did was to read and offset the first 8 bytes of the file and convert them into a string. // 0-8 bytes [file seekToFileOffset:0]; NSData *b = [file readDataOfLength:8]; NSUInteger capacity = [b length] * 2; NSMutableString *stringBuffer = [NSMutableString stringWithCapacity:capacity]; const unsigned char *dataBuffer = [b bytes]; NSInteger i; for (i=0; i<[b length]; ++i) { [stringBuffer appendFormat:@"%02X", (NSUInteger)dataBuffer[i]]; } NSLog(@"0-8 bytes HEXADECIMAL: %@",stringBuffer); As you can see, 0x3700000000000000 is the next 8 bytes. The only changes I would have to make to access the next 8 bytes would be to change the value of SeekFileToOffset to 8, so as to access the next 8 bytes of data. All in all, the solution you gave me is useful, however it would not be practical to enter the hexadecimal values manually. If formatting the bytes as a string and then parsing them is not the way to do it, then how do I access the first 8 bytes of the data directly and cast them into a byte pointer?

    Read the article

  • Drill down rss reader iphone

    - by bing
    Hi everyone, I have made a simple rss reader. The app loads an xml atom file in an array. Now I have added categories to my atom feed, which are first loaded in the array What is the best way to add drill down functionality programmatically. Now only the categories are loaded into the array and displayed. This is the implementation code ..... loading xml file <snip> ..... - (void)parserDidStartDocument:(NSXMLParser *)parser { NSLog(@"found file and started parsing"); } - (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError { NSString * errorString = [NSString stringWithFormat:@"Unable to download story feed from web site (Error code %i )", [parseError code]]; NSLog(@"error parsing XML: %@", errorString); UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [errorAlert show]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //NSLog(@"found this element: %@", elementName); currentElement = [elementName copy]; if ([elementName isEqualToString:@"entry"]) { // clear out our story item caches... Categoryentry = [[NSMutableDictionary alloc] init]; currentID = [[NSMutableString alloc] init]; currentTitle = [[NSMutableString alloc] init]; currentSummary = [[NSMutableString alloc] init]; currentContent = [[NSMutableString alloc] init]; } } - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ //NSLog(@"ended element: %@", elementName); if ([elementName isEqualToString:@"entry"]) { // save values to an entry, then store that item into the array... [Categoryentry setObject:currentTitle forKey:@"title"]; [Categoryentry setObject:currentID forKey:@"id"]; [Categoryentry setObject:currentSummary forKey:@"summary"]; [Categoryentry setObject:currentContent forKey:@"content"]; [categories addObject:[Categoryentry copy]]; NSLog(@"adding category: %@", currentTitle); } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ //NSLog(@"found characters: %@", string); // save the characters for the current item... if ([currentElement isEqualToString:@"title"]) { [currentTitle appendString:string]; } else if ([currentElement isEqualToString:@"id"]) { [currentID appendString:string]; } else if ([currentElement isEqualToString:@"summary"]) { [currentSummary appendString:string]; } else if ([currentElement isEqualToString:@"content"]) { [currentContent appendString:string]; } } - (void)parserDidEndDocument:(NSXMLParser *)parser { [activityIndicator stopAnimating]; [activityIndicator removeFromSuperview]; NSLog(@"all done!"); NSLog(@"categories array has %d entries", [categories count]); [newsTable reloadData]; }

    Read the article

  • Objective-C NSDate memory issue (again)

    - by Toby Wilson
    I'm developing a graphing application and am attempting to change the renderer from OpenGL to Quartz2D to make text rendering easier. A retained NSDate object that was working fine before suddenly seems to be deallocating itself, causing a crash when an NSMutableString attempts to append it's decription (now 'nil'). Build & analyse doesn't report any potential problems. Simplified, the code looks like this: NSDate* aDate -(id)init { aDate = [[NSDate date] retain] return self; } -(void)drawRect(CGRect)rect { NSMutableString* stringy = [[NSMutableString alloc] init]; //aDate is now deallocated and pointing at 0x0? [stringy appendString:[aDate description]]; //Crash } I should stress that the actual code is a lot more complicated than that, with a seperate thread also accessing the date object, however suitable locks are in place and when stepping through the code [aDate release] is not being called anywhere. Using [[NSDate alloc] init] bears the same effect. I should also add that init IS the first function to be called. Can anyone suggest something I may have overlooked, or why the NSDate object is (or appears to be) releasing itself?

    Read the article

  • Adding items to a combo box's internal list programatically.

    - by Andrew
    So, despite Matt's generous explanation in my last question, I still didn't understand and decided to start a new project and use an internal list. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { codesList = [[NSString alloc] initWithContentsOfFile: @".../.../codelist.txt"]; namesList = [[NSString alloc] initWithContentsOfFile: @".../.../namelist.txt"]; codesListArray = [[NSMutableArray alloc]initWithArray:[codesList componentsSeparatedByString:@"\n"]]; namesListArray = [[NSMutableArray alloc]initWithArray:[namesList componentsSeparatedByString:@"\n"]]; addTheDash = [[NSString alloc]initWithString:@" - "]; flossNames = [[NSMutableArray alloc]init]; [flossNames removeAllObjects]; for (int n=0; n<=[codesListArray count]; n++){ NSMutableString *nameBuilder = [[NSMutableString alloc]initWithFormat:@"%@", [codesListArray objectAtIndex:n]]; [nameBuilder appendString:addTheDash]; [nameBuilder appendString:[namesListArray objectAtIndex:n]]; [comboBoz addItemWithObjectValue:[NSMutableString stringWithString:nameBuilder]]; [nameBuilder release]; } } So this is my latest attempt at this and the list still isn't showing in my combo box. I've tried using the addItemsWithObjectValues outside the for loop along with the suggestions at this question: Is this the right way to add items to NSCombobox in Cocoa ? But still no luck. If you can't tell, I'm trying to combine two strings from the files with a hyphen in between them and then put that new string into the combo box. There are over 400 codes and matching names in the two files, so manually putting them in would be a huge chore, not to mention, I don't see what would be causing this problem. The compiler shows no warnings or errors, and in the IB, I have it set to use the internal list, but when I run it, the list is not populated unless I do it manually. Some things I thought might be causing it: Being in the applicationDidFinishLaunching: method Having the string and array variables declared as instance variables in the header (along with @property and @synth done to them) Messing around with using appendString multiple times with NSMutableArrays Nothing seems to be causing this to me, but maybe someone else will know something I don't. Thanks for the help.

    Read the article

  • NSCollectionView: Can the same object not be in the array more than once or is this a bug?

    - by Sean
    I may be doing this all wrong, but I thought I was on the right track until I hit this little snag. Basically I was putting together a toy using NSCollectionView and trying to understand how to hook that all up using IB. I have a button which will add a couple of strings to the NSArrayController: The first time I press this button, my strings appear in the collection view as expected: The second time I press the button, the views scroll down and room is made - but the items don't appear to get added. I just see blank space: The button is implemented as follows (controller is a pointer to the NSArrayController I added in IB): - (IBAction)addStuff:(id)control { [controller addObjects:[NSArray arrayWithObjects:@"String 1",@"String 2",@"String 3",nil]]; } I'm not sure what I'm doing wrong. Rather than try to explain all the connections/binds/etc, if you need more info, I'd be grateful if you could just take a quick look at the toy project itself. UPDATE: After more experimentation as suggested by James Williams, it seems the problem stems from having multiple objects with the same memory address in the array. This confuses either NSArrayController or NSCollectionView (not sure which). Changing my addStuff: to this resulted in the behavior I originally expected: [controller addObjects:[NSArray arrayWithObjects:[NSMutableString stringWithString:@"String 1"],[NSMutableString stringWithString:@"String 2"],[NSMutableString stringWithString:@"String 3"],nil]]; So the question now, I guess, is if this is a bug I should report to Apple or if this is intended/documented behavior and I just missed it?

    Read the article

1 2 3 4 5  | Next Page >