iphone,objective-c,ios,xcode,cocoa-touchRelated issues-Collection of common programming errors


  • sobox studio
    iphone ios ipad animation uinavigationcontroller
    I know this is an error that has been explained at length in numerous other questions. However it still seems to be a topic for debate as its highly subjective. I have two questions;How detrimental is this error?I’ve been working on an app that requires a custom UINavigationController. I create a false root that allows me to change the perceived root more easily. To create this affect I ‘pop’ to the false root then immediately ‘push’ the new one. Like this;[self popToViewController:self.fakeRoot

  • gcamp
    iphone
    I have string like 123-123-1234 so I want to convert string into this format (123) 123-1234 so any idea to develop this functionality.Thanks in advance.

  • RexOnRoids
    iphone sqlite sqlite3
    I’m using a few sqlite3_bind routines (in the iPhone SDK) as shown below to make a single update (INSERT or UPDATE) to a table:sqlite3_bind_text(update_statement, 1, aString, -1, SQLITE_TRANSIENT);sqlite3_bind_int(update_statement, 2, anInteger);sqlite3_bind_int(update_statement, 3, pk);However, upon checking the updated table I discover unexpected results. I followed the progress using ‘step over’ in the Xcode Debugger and it looks like this group of three sqlite3_bind routines is being looped

  • rickharrison
    iphone nsdate nsdateformatter
    I am trying to do some basic operations with Dates on the iPhone. I want to take a string like “2010-02-19” and turn it into a string like “Friday, Feb 19.” The strings I will be receiving will always be in 2010-02-19. Right now, I am running the following code that works, but it produces a warning that says “NSDate may not respond to +dateWithNaturalLanguageString:”NSDate *date = [NSDate dateWithNaturalLanguageString:scheduled]; NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelea

  • DA.
    iphone safari hover
    I’m experimenting with ways to have tooltips work across a variety of mobile devices. Unfortunately, the span of devices I need to support ranges from Nokias to iPhones.Unfortunately, some of the browsers I’m dealing with don’t support the use of the title attribute for tooltips on focus. As such, I need to come up with a different solution.For starters, I’m playing with pure-css tooltips: http://psacake.com/web/jl.aspThis method uses the :hover pseudo class to position and set the z-index of a

  • Danial
    iphone objective-c memory-management memory-leaks nsdictionary
    In my application I have a connection to an sqlite3 database. I have made a wrapper class, in this wrapper class I have an NSMutableDictionary and NSMutableArray.Each time a query is run I removeAllObjects from the dictonary and the array in the rapper class (I don’t release it). I then add the results from the query to the array and dictionary. The dictionary contains another subdictionaries.I have a tableViewController, in this class I get data from the database using my rapper class and copy

  • Tullio Onion Sebastiani
    iphone objective-c ios6 storyboard navigationcontroller
    I’m developing an iOS6 App with storyboards and i’m encountering an unexpected beahviour. My app is almost in portrait mode , and i would keep this orientation in all the views except two.For this reason the project supports both landscape and portrait mode, i’ve subclassed navigation controller with a category (as explained almost everywhere :-)in Appdelegate.m and every view controller implements – (NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskPortrait; (landscap

  • Alexi Groove
    iphone objective-c ocmock
    I want to unit test the custom init method of a class that inherits from NSURLConnection — how would I do this if the init of my testable class invokes NSURLConnection’s initWithRequest?I’m using OCMock and normally, I can mock objects that are contained within my test class. For this inheritance scenario, what’s the best approach to do this?- (void)testInit { id urlRequest = [OCMockObject mockForClass:[NSURLRequest class]];MyURLConnectionWrapper *conn = [[MyURLConnectionWrapper alloc] initWi

  • msgambel
    iphone objective-c ipad settings volume
    Currently, I’m setting the volume to max, and then checking if the volume is at max, or a lower value. If it’s at a lower value, then the user must have a Volume Lock on their system.This works fine, but I’m wondering if there is some method to call, or property to check which tells me this in code for free? I’ve been looking online as to how to do this, but I can’t seem to find anything. Thanks in advance!Edit: It turns out that my previous method of setting the max volume and then checking if

  • Vikings
    iphone objective-c ios4 iphone-sdk-3.0
    I am having unexpected results with my application. I am using a settings bundle, and I want to the default switch to turn on. The switches are off when I start my application. But the sound and the shake are working. I just want the switch to be one when my application loads, and the sound and the shake to be enabled.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Set the application defaultsNSUserDefaults *defaults = [NSU

  • epologee
    objective-c interface coding-style implementation
    If you write method implementations in Objective-C, it is pretty standard to sum up the methods of a class in the corresponding @interface blocks. Publically accessible methods go in the header file’s interface, not-so-public methods can go in an empty category on top of the implementation file.But it’s not neccessary to declare an interface for every method. If you only reference the methods below their implementation code of the same class/file, there’s no need to put any declaration anywhere

  • Cristian Civera
    c++ ios objective-c opencv
    I’m using this function to convert UIImage to Mat- (cv::Mat)cvMatFromUIImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage); CGFloat cols = image.size.width; CGFloat rows = image.size.height;cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels (color channels + alpha)CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to datacols, // Width of bitmaprows, // Heig

  • Zephyer
    objective-c json parsing afnetworking
    im trying to parse some JSON. for simplicity ill explain using the default example at github: when running:NSURL *url = [NSURL URLWithString:@”http://httpbin.org/ip”]; NSURLRequest *request = [NSURLRequest requestWithURL:url];AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {NSLog(@”IP Address: %@”, [JSON valueForKeyPath:@”origin”]);} failure:nil];[operation start];i get

  • Ben
    ios objective-c cocoa-touch nsdate nsdateformatter
    In short words I plan to get current dateTime, change the time and make it local to Malaysia Time by applying +0800 to timezone.The result is unexpected :-(NSDate *)departureDateTime {NSDate *date = [NSDate date];NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];[components setHour: 7];[components setMinute: 59];[components setSecond: 17];NSDate *newDate = [gregorian dat

  • horseshoe7
    ios objective-c core-data nsmanagedobject mogenerator
    I have a project using CoreData. I use Mogenerator to generate the subclasses.When I set the value of a property, this value isn’t actually assigned. Each subsequent time I try to set the value, the previous value I set it to was not assigned.This worked fine as my underlying data framework was Mantle, but since moving to CoreData, this stopped working. I rely on KVO to keep some UIView objects up-to-date with the model.Again, the ivars of a CoreData NSManagedObject subclass do not seem to ta

  • John
    objective-c xcode4 ios-sdk-4.3 aqgridview
    I am new in Iphone development . Now, i am trying to develop an AQGridView in iphone . I downloaded the zip file of AQGridView from Github socil coding site. The example application of AQGridView (ImageDemo,SpringBoard,ExpanderDemo) can not run in xcode 4 and ios sdk 4.3.At compail time they showing some error “AlanQuatermain-AQGridView-4072978/Examples/ImageDemo/main.m:14:5: error: unexpected ‘@’ in program [3]”The error indicator shown at main(). The code of main() is bellow.int main(int argc

  • Krishnan
    objective-c memo
    I came to know that, it is better to use copy on @property of NSString than retain due to the problems you can get if you are provided with a NSMutableString. Is the same condition holds true for NSArray , NSDictionary, NSMutableData ?

  • Danial
    iphone objective-c memory-management memory-leaks nsdictionary
    In my application I have a connection to an sqlite3 database. I have made a wrapper class, in this wrapper class I have an NSMutableDictionary and NSMutableArray.Each time a query is run I removeAllObjects from the dictonary and the array in the rapper class (I don’t release it). I then add the results from the query to the array and dictionary. The dictionary contains another subdictionaries.I have a tableViewController, in this class I get data from the database using my rapper class and copy

  • Tullio Onion Sebastiani
    iphone objective-c ios6 storyboard navigationcontroller
    I’m developing an iOS6 App with storyboards and i’m encountering an unexpected beahviour. My app is almost in portrait mode , and i would keep this orientation in all the views except two.For this reason the project supports both landscape and portrait mode, i’ve subclassed navigation controller with a category (as explained almost everywhere :-)in Appdelegate.m and every view controller implements – (NSUInteger)supportedInterfaceOrientations{return UIInterfaceOrientationMaskPortrait; (landscap

  • Alexi Groove
    iphone objective-c ocmock
    I want to unit test the custom init method of a class that inherits from NSURLConnection — how would I do this if the init of my testable class invokes NSURLConnection’s initWithRequest?I’m using OCMock and normally, I can mock objects that are contained within my test class. For this inheritance scenario, what’s the best approach to do this?- (void)testInit { id urlRequest = [OCMockObject mockForClass:[NSURLRequest class]];MyURLConnectionWrapper *conn = [[MyURLConnectionWrapper alloc] initWi

  • sobox studio
    iphone ios ipad animation uinavigationcontroller
    I know this is an error that has been explained at length in numerous other questions. However it still seems to be a topic for debate as its highly subjective. I have two questions;How detrimental is this error?I’ve been working on an app that requires a custom UINavigationController. I create a false root that allows me to change the perceived root more easily. To create this affect I ‘pop’ to the false root then immediately ‘push’ the new one. Like this;[self popToViewController:self.fakeRoot

  • Cristian Civera
    c++ ios objective-c opencv
    I’m using this function to convert UIImage to Mat- (cv::Mat)cvMatFromUIImage:(UIImage *)image { CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage); CGFloat cols = image.size.width; CGFloat rows = image.size.height;cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels (color channels + alpha)CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to datacols, // Width of bitmaprows, // Heig

  • maroxe
    ios block afnetworking
    In my app when the user presses a button I start a HTTP asynchronous request (using AFURLConnectionOperation) and change the text of UILabel in the completionHandler block. This change, however, does not take place when the request is concluded and instead happens around 2-3 seconds later. Below is a code snippet that results in this behavior.AFURLConnectionOperation* operation = …[opration setCompletionBlock:^{NSLog(@”This text appears immediatly”);[myLabel setText:@”this one is delayed for 2

  • Ben
    ios objective-c cocoa-touch nsdate nsdateformatter
    In short words I plan to get current dateTime, change the time and make it local to Malaysia Time by applying +0800 to timezone.The result is unexpected :-(NSDate *)departureDateTime {NSDate *date = [NSDate date];NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];[components setHour: 7];[components setMinute: 59];[components setSecond: 17];NSDate *newDate = [gregorian dat

  • Beijing_Rick
    ios xcode segue pushviewcontroller
    My segues were added in the storyboard. I want push to a viewController, say Deep_VC, different from the next one in the storyboard, say Next_VC. I’m using:Deep_VC *controller = [self.storyboard instantiateViewControllerWithIdentifier:@”DeepVC”]; [self.navigationController pushViewController:controller animated:YES];It goes there, but I get errors. The nav bar tile is for the Next_VC, not the Deep_VC, and the error messages:Finishing up a navigation transition in an unexpected state . . . Unb

  • horseshoe7
    ios objective-c core-data nsmanagedobject mogenerator
    I have a project using CoreData. I use Mogenerator to generate the subclasses.When I set the value of a property, this value isn’t actually assigned. Each subsequent time I try to set the value, the previous value I set it to was not assigned.This worked fine as my underlying data framework was Mantle, but since moving to CoreData, this stopped working. I rely on KVO to keep some UIView objects up-to-date with the model.Again, the ivars of a CoreData NSManagedObject subclass do not seem to ta

  • Marc
    ios accelerometer core-motion
    I’m seeing some unexpected readings from the userAcceleration field in CMDeviceMotion. When I look at the raw accelerometer data from CMAccelerometerData, I see that if the iPhone is flat on a table the reading is 1G straight down (1G in -Z axis) and if I drop the iphone (on a soft surface of course) then the acceleromtere reading goes to zero as expected. That’s all fine. When I instead use the CMDeviceMotion class, the userAcceleration reading is zero as expected when the iPhone is flat on tab

  • rmaddy
    ios asynchronous dialog
    So I normally write apps for android and just use an async task to call methods to run in the background while an alert dialog plays saying “Loading” or something like that. On this app Im trying to translate to iOS, Im parsing data from different websites and displaying a couple web images and I want to have my alart dialog play while all these things are being loaded. Ive been searching for hours and havent found the solution I am looking for. I was hoping someone could point me to a tutorial

  • rmaddy
    ios uinavigationcontroller master-detail
    I have a tableview set up as a Master-Detail view for iPad and I am having a problem with the navigation getting corrupted. The link between the Master and Detail is a Push-Detail split, I need it this way as the user can then navigate within the detail and the master stays as what it is. The problem is that if you tap through the Master side too quickly I get navigation corrupted messages such as Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get

  • Viktor
    c++ ios objective-c c static-libraries
    I have some C++ code (exposing a C-only interface through a header) which I will use for an iOS project.I can either create a static library and link to this from my app project, or add the source files directly to the app project – which option is best?All answers appreciated!

  • Beijing_Rick
    ios xcode segue pushviewcontroller
    My segues were added in the storyboard. I want push to a viewController, say Deep_VC, different from the next one in the storyboard, say Next_VC. I’m using:Deep_VC *controller = [self.storyboard instantiateViewControllerWithIdentifier:@”DeepVC”]; [self.navigationController pushViewController:controller animated:YES];It goes there, but I get errors. The nav bar tile is for the Next_VC, not the Deep_VC, and the error messages:Finishing up a navigation transition in an unexpected state . . . Unb

  • Ethen A. Wilson
    objective-c xcode compiler-errors
    My code used to work fine, but I was working in my main controller’s implementation when I noticed the code colors weren’t right. When I hit run to have Xcode compile the code, I got every line of code as some kind of error in two of my header files. I have more header files, and I think they would have these weird errors too, but my guess is there was too many errors and it stopped.For @interface, I get the errorUnexpected token after Objective-C stringFor every other method, I get Missing cont

  • Thanks
    iphone cocoa-touch xcode uikit provisioning
    Yesterday I testet a lot on my device. Suddenly I get this error message when I hit Build & Go in Xcode. First, it asks me if it’s ok to sign with my key. I click yes, and then that error message appears. My iPod is connected as usual, iTunes starts automatically and I close that to prevent interruptions.I tried restarting Xcode. Doesn’t help. My Apple Dev Enrollment is brand new. Any idea what the problem might be?Edit: In Window > Organizer I can see this message: Your mobile device has en

  • Alan
    ios objective-c xcode uiscrollview uitableviewcontroller
    In my view I am using a UITableView that is controlled by a UITableViewController on the top half of the screen. The remaining screen is used for a UIScrollView that contains a view that is controlled by the main UIViewController. When I perform a pull down to refresh in the UITableViewController, (for some reason if the number of table entries is less than or greater than the initial load value, the UIScrollView in the main UIViewController’s frame gets changed to the screensize… Essentially

  • Kellan Hilscher
    ios xcode uicollectionview
    I am having an issue adding labels to individual cells in a UICollectionView. Using the code shown bellow, the label is added only to the first cell in the collection and none of the others. However, if I change cell.contentView in the third to last line to collectionView, the labels are all added to the right locations, which means I’m dealing with at least the right frame, but I need the labels to be added to the cells themselves.- (UICollectionViewCell *)collectionView:(UICollectionView *)col

  • Ramshad
    iphone objective-c xcode automatic-ref-counting
    Possible Duplicate:iOS: to ARC or not to ARC? Pros and Cons i have learned about What are the advantages and disadvantages of using ARC?from What are the advantages and disadvantages of using ARC?However i still doubt in automatic reference counting (ARC).I have some queries here.We don’t want to do the release manually, if the ARC is active?is it do the automatic garbage collection and memory management automatically?Could any one please clarify my thoughts.

  • OracleUser
    ios objective-c xcode exception ios7
    Am new to the iOS development. While looking into one of the App I work on, with exception breakpoint enabled in xcode. I see so many repetitive exceptions been raised.But till now, we never realised this, as iOS was excusing those exceptions. The main exception was happening in our service layer, where, in an XML parsing, one of the element mentioned as key was missing. since so many back end requests are fired, for every XML response, and for multiple items inside it, this exception is thrown.

  • Sam Rad
    iphone ios xcode background foreground
    I would like to know if there’s a way to keep an app running in foreground, during a specific interval time. I have a thread running exactly during 3 minutes and I need that the user cannot leave the app. If such a thing is not possible I’m going to ask another question. I could let that the user set the app in background mode because I use the applicationDidEnterBackground:(UIApplication *)application method to save the data I need but if the user clicks the power button, how could I save the d

  • Chris Markle
    ios xcode xctest
    Just starting to work with XCTest in Xcode 5 ( (Xcode Version 5.0.2 [5A3005]). I made a sample test file where I test that true is true. It works and the test passes as expected. When I add an NSLog statement in front of the assertion, the test fails with a message “test_case did not finish” where “test_case” is my test method name (testTrue in my case).Here’s test1.m in the failing case. The only difference between failing and working is that the failing case has an NSLog in the test method. (I

  • Peter Hosey
    xcode profiling xcodebuild gcov
    Let’s get this out of the way first: This question is not a duplicate of this earlier question. I’ll explain why below.I’m running the command xcodebuild test -scheme ‘ISO8601ForCocoa’ SYMROOT=../build, and here’s the output:Executed 16 tests, with 0 failures (0 unexpected) in 0.047 (0.051) seconds profiling: invalid magic number (0x656d6954) profiling: invalid magic number (0x00000000) ** TEST SUCCEEDED **The person who asked that earlier question got the same error message, but they fixed it b

  • Ben
    ios objective-c cocoa-touch nsdate nsdateformatter
    In short words I plan to get current dateTime, change the time and make it local to Malaysia Time by applying +0800 to timezone.The result is unexpected :-(NSDate *)departureDateTime {NSDate *date = [NSDate date];NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];[components setHour: 7];[components setMinute: 59];[components setSecond: 17];NSDate *newDate = [gregorian dat

  • Thanks
    iphone cocoa-touch xcode uikit provisioning
    Yesterday I testet a lot on my device. Suddenly I get this error message when I hit Build & Go in Xcode. First, it asks me if it’s ok to sign with my key. I click yes, and then that error message appears. My iPod is connected as usual, iTunes starts automatically and I close that to prevent interruptions.I tried restarting Xcode. Doesn’t help. My Apple Dev Enrollment is brand new. Any idea what the problem might be?Edit: In Window > Organizer I can see this message: Your mobile device has en

  • Jeff Kelley
    cocoa-touch ipad orientation
    I have a UIViewController one UIWebView in it. I’d like the UIWebView to be positioned in the centre of the iPad screen in landscape and portrait modes. So, I’ve implemented it like this// UIViewController // InfoGraphicView is the UIWebView-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {// Overriden to allow any orientation.return YES; }- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)dur

  • Jav_Rock
    objective-c cocoa-touch ios5
    I’m new at this so thanks in advance for any help here.I’m just playing around with a little exercise in iOS and I have 2 different things calling the same routine.Each of these message calls passes along sender. One of these is a UIButton that calls when touchUpInside, one is a UISegmentedControl that calls when valueChanges.I need to handle the initial part slightly differently within the same method and i know that somehow I use sender.What I need to do is to ask if sender is a UIButton or if

  • Krumelur
    cocoa-touch monotouch catransform3d
    In viewWillAppear I want to adjust some of my views using the following transformation (Monotouch code):CATransform3D oTransform3D = CATransform3D.Identity; oTransform3D.m34 = 1.0f / -400; oTransform3D = oTransform3D.Translate( 110, 0, 0); oTransform3D = oTransform3D.Rotate( (-70f) * (float)Math.PI / 180f, 0, 1, 0); However, this causes the view to be rendered far left of the screen. If I put the very same code in viewDidAppear, it is working. I have already checked that all views have valid s

  • Peter Warbo
    objective-c ios cocoa-touch
    Is there a way to delay the screen capture made by iOS when app is entering background? The reason is that I’m sometimes showing a view when the user goes to home screen I want this view removed so it doesn’t show when app is resumed. The view in question is a SSHUDView (source code here) which I call dismissAnimated:NO in applicationWillResignActive. This actually works in the simulator but not on real device (the SSHUDView still shows when resuming). Anyone have a clue how to deal with this?

  • atxe
    objective-c ios cocoa-touch uiview setneedsdisplay
    I have a UIViewController and in willRotateToInterfaceOrientation, i am calling [self view] setNeedsLayout]; This view call’s it’s subview’s (a UIScrollView) layoutSubviews method, but the UIScrollView doesn’t call layoutSubviews for it’s subviews. Is this how it’s suppose to be? I thought if you call setNeedsLayout on a view, it will call layoutSubviews on each and every subivew and their subviews and on…Do I have to manually, override layoutsubview in UIScrollView and call setNeedsDisplay fo

  • kender
    iphone cocoa-touch memory-management cocos2d-iphone
    I have an iPhone application in Cocos2d that sometimes crashes on actual device, due to memory problems. What I have so far found out is that the scenes, when switched, aren’t fully released – the [retainCount] for them is somewhat about 4-10 🙂 The dealloc method never gets called, and then I assume, when I switch the scenes a few times, the memory issue shows up. I’m wondering – where should I relese the scene? Since it has number of children, I suppose I should be doing a cleanup-removal of t

  • NDakotaBE
    ios cocoa-touch uitableview uiview uiscrollview
    For work purposes I need to create a UIScrollView which embeds a UIView which in his turn embeds an UITableView via the container feature in Xcode.My UIScrollView is a full page scrollview with Paging enabled. My UIView is filled with a UIImage, some UIButton’s and a container linking to a UITableView. On initial launch, the data is loaded perfectly, meaning the UITableView is filled with the data, the UIImage is filled, and the Buttons are placed correctly. But for some strange reason the when

  • vikingosegundo
    objective-c cocoa-touch
    I’m a real noob to objective C but I CANNOT figure out how to push transition from one view to another on a button click. What I’m doing wrong here? I’ve #imported my Page2.h file in the headerI get these two errors 1 “unexpected interface name ‘Page2’: expected expression”2 “No known Class method for selector ‘setFrame’- (IBAction)Page2Switcher:(id)sender {CGRect inFrame = [_Page1 frame];CGRect outFrame = Page2;outFrame.origin.x -= inFrame.size.width;[UIView beginAnimations:nil context:nil];[UI

Web site is in building