BuySellAds.com

If you like my tutorials, you will love my book . It is chockful of advanced programming techniques and the only comprehensive barcode reference for serious iOS developers.
Our DNA is written in Objective-C
Jump

Category Archive for ‘Q&A’ rss

“Are You a Cocoa Crack?” Quiz (2)

It’s been more than half a year since I published the first installment of this Quiz aimed at Cocoa Cracks. Back then people seemed to like the challenges I presented. So I collected a few more nuggets. If you ever stumbled on an crash or strange result that you did not expect, then mail it to me.

These questions will show if you are really the Cocoa Crack you like to believe to be. To see the answer highlight the answer text with your mouse. No peeking! Respond in the comments how many you got correct.

Quiz: Warm Up. Your UI designer gave you a PNG with the instruction “just tile this in the background” of a UIView. Do you have to subclass UIView, overriding the drawRect of the view and performing drawImage for all tiles? Or is there a simpler method?

Answer: You create a UIImage by loading the PNG and then create a “color” from it with [UIColor colorWithPatternImage:image]. Then you apply this as the background color of the view.


Quiz: Suddenly your app crashes and when the debugger opens it first loads lots of stack frames. All you did is override a property like shown below. What’s the bug? Bonus Question: where’s the memory leak?

- (void) setTextColor:(UIColor *)newTextColor
{
	if (newTextColor != textColor)
	{
		[textColor release];
 
		if (newTextColor)
		{
			self.textColor = [newTextColor retain];
		}
		else // default
		{
			self.textColor = [[UIColor whiteColor] retain];
		}
		bubbleView.highlightedTextColor = textColor;
	}
}

Answer: You have an endless recursion. self.textColor is a simplified way to write [self setTextColor:]. So this method keeps calling itself until the stack is full and your app gets terminated. The leak is calling retain on an assignment to a retaining property. But if you fix the crashing bug by removing both self then there is no leak.


Quiz: You want to draw two lines in a drawRect, a horizontal black line and a white line 1 pixel below it. So you write the following code. But instead of the intended result you get this picture in magnification, the black is dark gray and the white is a lighter shade of gray. Why is that and how would you fix it?

CGContextRef currentContext = UIGraphicsGetCurrentContext();
 
// Draw a black line at the top and a white line 1 pixel below
 
CGContextSetLineWidth(currentContext, 1);
 
CGContextSetRGBStrokeColor(currentContext, 0.0, 0.0, 0.0, 1.0); // Black
CGContextMoveToPoint(currentContext, 0, 0); // top left
CGContextAddLineToPoint(currentContext, rect.size.width, 0); // to top right
CGContextStrokePath(currentContext);
 
CGContextSetRGBStrokeColor(currentContext, 1.0, 1.0, 1.0, 1.0); // White
CGContextMoveToPoint(currentContext, 0, 1); // left
CGContextAddLineToPoint(currentContext, rect.size.width, 1);
CGContextStrokePath(currentContext);

Answer: Core Graphics does not work on pixels directly, that’s why you use floating point numbers for coordinates. It works on coordinates and the resulting bitmap is always rendered. Half of the line width is always applied half a unit to each side of the line. To remedy this you need to move the coordinates of the lines by half a unit up or down.

(Thanks to Michael Kaye for sending this in)


Quiz: You have a UITableView and would like for it to have rounded corners. What’s the fastest way to achieve that? Which header is necessary?

Answer: You can have any UIView have rounded corners by setting the cornerRadius property of it’s CALayer. The layer of a UIView is actually what’s responsible for drawing the contents of the view. You need: to import


Quiz: You have created a UIViewController which shows a UIWebView and has a navigation bar. You want to set the title on the bar to be the same as the title of the HTML document once loading has finished. Would you need to parse the HTML with NSScanner to find the tag and extract it? Or is there a simpler method?</p> <p><strong>Answer:</strong> <span style="color: #fbfbfb">In the webViewDidFinishLoad: delegate method you retrieve the title via javascript and set it like that. self.title = [webView stringByEvaluatingJavaScriptFromString: @”document.title”];<br /> </span></p> <hr /> <p><strong>Quiz: </strong>You have written code to load some UIImages in the background (performSelectorOnBackgroundThread or NSInvocationOperation). The loading code calls the method below to resize the loaded image. This has “always working before”, but suddenly you keep getting a EXC_BAD_ACESS on the line marked. You have double checked all retains and even set NSZombieEnabled to YES because usually you get this message if you are using an overreleased object. But that did not fix the problem. What’s the reason for the crash and how would you fix it?</p> <div class="wp_codebox"><table><tr id="p18663"><td class="code" id="p1866code3"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">+</span> <span style="color: #002200;">(</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">)</span>imageWithImage<span style="color: #002200;">:</span><span style="color: #002200;">(</span>UIImage<span style="color: #002200;">*</span><span style="color: #002200;">)</span>image scaledToSize<span style="color: #002200;">:</span><span style="color: #002200;">(</span>CGSize<span style="color: #002200;">)</span>newSize; <span style="color: #002200;">{</span> UIGraphicsBeginImageContext<span style="color: #002200;">(</span> newSize <span style="color: #002200;">)</span>; <span style="color: #002200;">[</span>image drawInRect<span style="color: #002200;">:</span>CGRectMake<span style="color: #002200;">(</span><span style="color: #2400d9;">0</span>,<span style="color: #2400d9;">0</span>,newSize.width,newSize.height<span style="color: #002200;">)</span><span style="color: #002200;">]</span>; <span style="color: #11740a; font-style: italic;">// &lt;- crash</span> UIImage<span style="color: #002200;">*</span> newImage <span style="color: #002200;">=</span> UIGraphicsGetImageFromCurrentImageContext<span style="color: #002200;">(</span><span style="color: #002200;">)</span>; UIGraphicsEndImageContext<span style="color: #002200;">(</span><span style="color: #002200;">)</span>;   <span style="color: #a61390;">return</span> newImage; <span style="color: #002200;">}</span></pre></td></tr></table></div> <p><strong>Answer:</strong> <span style="color: #fbfbfb">UIKit is not thread-safe. Therefore all drawing via UIKit needs to happen on the main thread. The UIGraphicsBeginImageContext works to create the context, but the memory for it is owned to the main thread and trying to access it with drawInRect from another thread is causing this exception. To fix it you need to rewrite this method to create your own bitmap context on the non-main thread so that you then own the memory for it. After creating the bitmap context you draw the image to it with CGContextDrawImage and then create a new CGImage with CGBitmapContextCreateImage. From the CGImage you create a UIImage to return from the method.</span></p> <hr /> <p><strong>Quiz: </strong>Off the top of your head: how many methods do you know of having a piece of code contained in one method being performed in the background? Which?</p> <p><strong>Answer:</strong> <span style="color: #fbfbfb">Correct Answers are: performSelectorOnBackgroundThread and creating an NSInvocationOperation from the selector as those work on an existing method. Creating an NSOperation sub-class or manual threading with NSThread are also valid answers, but those require that you move the code into a new class or need to be well versed with threading voodoo.<br /> </span></p> <hr /> <p>So how many answers did you know? Be honest! If you also have a Cocoa riddle like these to contribute please mail them directly to me (oliver@drobnik.com) and I will publish them in this format.</p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2010/02/are-you-a-cocoa-crack-quiz-2/#comments" class="button_gray comments">6 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> </div> <div class="leaderboard_ad"> <!-- Ad code goes here --> <div id="advman-3" class="widget Advman_Widget"><h3 class="widgettitle"></h3><!-- BuySellAds.com Zone Code --> <div id="bsap_1260346" class="bsarocks bsap_fc3166ea4a479e0fdb4251fbe92a1219"></div> <!-- End BuySellAds.com Zone Code --></div> </div> <div id="post-2054" class="post-2054 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/" rel="bookmark">UIImageView + Touch Handling = UIButton</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Feb 14, 2010 <span class="commentcount">(<a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/#comments">11</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/" rel="bookmark">Feb 14, 2010</a></p> <div class="entry"> <p>gdscei asks:</p> <blockquote><p>“Hello, how can i make an image view work as a button? I want it to be assigned to the ‘reload’ action of WebView.<br /> Can someone give me instructions how to do this?”</p></blockquote> <p>Often people start out constructing their UI visually, starting with this line of reasoning “I want to show an image. Ah, UIImageView”. So they create the visual appearance of their UI either by clicking it together in Interface Builder or – if slightly more advanced in their coding skills – creating those image views in code.</p> <p>So if we create a new view-based project in XCode, we could modify the viewDidLoad of the main view controller like this to show the image:</p> <div class="wp_codebox"><table><tr id="p20544"><td class="code" id="p2054code4"><pre class="objc" style="font-family:monospace;"><span style="color: #002200;">-</span> <span style="color: #002200;">(</span><span style="color: #a61390;">void</span><span style="color: #002200;">)</span>viewDidLoad <span style="color: #002200;">{</span> <span style="color: #002200;">[</span>super viewDidLoad<span style="color: #002200;">]</span>;   UIImageView <span style="color: #002200;">*</span>imageView <span style="color: #002200;">=</span> <span style="color: #002200;">[</span><span style="color: #002200;">[</span>UIImageView alloc<span style="color: #002200;">]</span> initWithFrame<span style="color: #002200;">:</span> CGRectMake<span style="color: #002200;">(</span><span style="color: #2400d9;">100.0</span>, <span style="color: #2400d9;">100.0</span>, <span style="color: #2400d9;">57.0</span>, <span style="color: #2400d9;">57.0</span><span style="color: #002200;">)</span><span style="color: #002200;">]</span>; imageView.image <span style="color: #002200;">=</span> <span style="color: #002200;">[</span>UIImage imageNamed<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">"Icon.png"</span><span style="color: #002200;">]</span>; <span style="color: #002200;">[</span>self.view addSubview<span style="color: #002200;">:</span>imageView<span style="color: #002200;">]</span>; <span style="color: #002200;">[</span>imageView release<span style="color: #002200;">]</span>; <span style="color: #002200;">}</span></pre></td></tr></table></div> <p>The next logical step in reasoning right after displaying the icon is now to get touch handling somehow. And that’s where you will get stuck because UIImageView is a dead end when it comes to reacting to the user’s finger.</p> <p> <a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/#more-2054" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/#more-2054">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2010/02/uiimageview-touch-handling-uibutton/#comments" class="button_gray comments">11 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div class="leaderboard_ad"> <!-- Ad code goes here --> </div> <div id="post-1777" class="post-1777 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/" rel="bookmark">Double Tapping on Buttons</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Dec 23, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/#comments">3</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/" rel="bookmark">Dec 23, 2009</a></p> <div class="entry"> <p>Grinarn asks:</p> <blockquote><p>“I got several buttons set up on my view and when the button gets clicked, a detailed view of that item appears.<br /> What I need is another action method like double click or click and hold, to trigger another action.</p> <p>How can I do this? I just found the events in the IB which seems only supports single touch events.”</p></blockquote> <p>Any view in the SDK can receive and process touch events. This gives you the ability to implement any kind of tap or gesture that you might dream up. But for everyday purposes we will find the methods provided by UIControl sufficient. UIControl inherits from UIView which means that it can do everything that views can do, but it adds the Target-Action mechanism.</p> <p>For this mechanism you can attach a multitude of various events to each control by simply specifying a target (= any object instance), an action (= any selector of the target) and a constant from the following list. “Selector” is only fancy name for method signature, which consists of the method name and the names of the parameters, all with a colon behind them.</p> <p><strong>General Touch Actions</strong></p> <ul> <li>UIControlEventTouchDown</li> <li>UIControlEventTouchDownRepeat</li> <li>UIControlEventTouchDragInside</li> <li>UIControlEventTouchDragOutside</li> <li>UIControlEventTouchDragEnter</li> <li>UIControlEventTouchDragExit</li> <li>UIControlEventTouchUpInside</li> <li>UIControlEventTouchUpOutside</li> <li>UIControlEventTouchCancel</li> </ul> <p><strong>Specific to Editing Controls</strong></p> <ul> <li>UIControlEventValueChanged</li> <li>UIControlEventEditingDidBegin</li> <li>UIControlEventEditingChanged</li> <li>UIControlEventEditingDidEnd</li> <li>UIControlEventEditingDidEndOnExit</li> </ul> <p><strong>Generic Constants matching several Actions</strong></p> <ul> <li>UIControlEventAllTouchEvents</li> <li>UIControlEventAllEditingEvents</li> <li>UIControlEventApplicationReserved</li> <li>UIControlEventSystemReserved</li> <li>UIControlEventAllEvents</li> </ul> <p>Now generally if you make a button then you would use the UIControlEventTouchUpInside event even though at first you might instinctively go for UIControlEventTouchDown. TouchUpInside is the standard as it allows the user to reconsider and move outside of the button before lifting his finger thus cancelling his action. Otherwise the button would be like a landmine where there is no way back after touching it.</p> <p>Now there might be cases where you exactly WANT the action to be fired right when you touch the control. Then TouchDown is the right action. You also see a TouchDownRepeat action available, but this always comes in succession after a TouchDown. Therefore some additional trickery is necessary to be able to distinguish between single and double tapping a button.</p> <p> <a href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/#more-1777" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/#more-1777">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/12/double-tapping-on-buttons/#comments" class="button_gray comments">3 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1691" class="post-1691 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/12/itunes-release-dates/" rel="bookmark">iTunes Release Dates</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Dec 05, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/12/itunes-release-dates/#respond">0</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/12/itunes-release-dates/" rel="bookmark">Dec 05, 2009</a></p> <div class="entry"> <p>Mingleboy asked Apple via E-Mail:</p> <blockquote><p>“Why does my updated app not appear amongst the new apps even though I changed the release date on iTunes Connect?”</p></blockquote> <p>We all remember that previously it was possible to hop to the first pages of iTunes by changing this date. And of course this “feature” was exploited quite a bit by developers hoping to achieve additional attention for their apps and thus additional sales.</p> <p>Apple recently fixed this to match what they originally intended, it appears now that it was a bug in the system anyway that Apple willingly ignored for some time until the gaming of release dates overboarded. I reported about this change in <a href="http://www.cocoanetics.com/2009/11/dr-touch-001/">Episode 1 of the Dr. Touch Podcast</a>.</p> <p> <a href="http://www.cocoanetics.com/2009/12/itunes-release-dates/#more-1691" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/12/itunes-release-dates/#more-1691">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/12/itunes-release-dates/#comments" class="button_gray comments">0 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1626" class="post-1626 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/" rel="bookmark">The World on an NSString</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Nov 25, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/#respond">0</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/" rel="bookmark">Nov 25, 2009</a></p> <div class="entry"> <p>When you are are newbie in programming objective-C then you might find somethings confusing when you start using strings. Coming from C you where used to using zero terminated C-Strings. Coming from other languages you might be challenged by the fact that there is no implicit type conversion like, for example, in BASIC.</p> <p>In regular C strings are pointers of type “char *”, meaning that it’s the memory address of a one byte character. The length of a C-String is determined by a binary zero ” at the end of it. Objective-C rarely uses those, instead NSString means the world to us.</p> <p>The core fundamental to realize first is that you are always dealing with pointers – that is addresses in memory – when using objects (instances of classes). So it simply does not make sense to compare strings with the == operator. Two variables pointing to NSString might or might not actually point to the same instance. (Actually the same was true for C-Strings, because the same text might or might not be contained in different memory regions referenced by char * pointers)</p> <p> <a href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/#more-1626" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/#more-1626">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/11/the-world-on-an-nsstring/#comments" class="button_gray comments">0 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1597" class="post-1597 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/11/asking-user-for-review/" rel="bookmark">Asking Users for a Review</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Nov 23, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/11/asking-user-for-review/#comments">9</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/11/asking-user-for-review/" rel="bookmark">Nov 23, 2009</a></p> <div class="entry"> <p><img class="alignright size-full wp-image-1599" style="margin-left: 10px;margin-bottom: 10px" src="http://i0.wp.com/www.cocoanetics.com/files/reviews.jpg?resize=192%2C288" alt="Reviews" data-recalc-dims="1" /></p> <p>Yves Gonzales asked:</p> <blockquote><p>“Would you know what the URL scheme is for writing a review in the AppStore, launched from within an app in iPhone, which opens AppStore? (I want to ask users to leave a review.)”</p></blockquote> <p>At first I answered that I did not think this was possible. But Yves, with the help of trusty Mr. Google discovered a better answer than mine. There is in fact a possibility to get the mobile App Store app to open on the review page for a specific app.</p> <p> <a href="http://www.cocoanetics.com/2009/11/asking-user-for-review/#more-1597" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/11/asking-user-for-review/#more-1597">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/11/asking-user-for-review/#comments" class="button_gray comments">9 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1552" class="post-1552 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/" rel="bookmark">Add one Week and Skip Weekend</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Nov 14, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/#respond">0</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/" rel="bookmark">Nov 14, 2009</a></p> <div class="entry"> <p>dbarret asks:</p> <blockquote><p>“I need some help with this issue and I’m hoping you have the time to point me in the right direction, here goes:</p> <ol> <li>I want to display today’s date in a UILabel, then with a button event, the tricky part…</li> <li>display a date 7 days in the future UNLESS it’s the weekend, then it will display the following Monday.</li> </ol> <p>So basically I want to display ONLY weekdays, no weekends… it that even possible?”</p></blockquote> <p>Of course it is possible. In this case it’s not even very difficult.</p> <p>I assume that you know how to display a UILabel and set its text. So in this article I’ll show how to enhance what we previously learned about adding days to NSDates and add extra code to also skip weekend days.</p> <p> <a href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/#more-1552" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/#more-1552">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/11/add-one-week-skip-weekend/#comments" class="button_gray comments">0 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1488" class="post-1488 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/" rel="bookmark">Ignoring Certificate Errors on NSUrlRequest</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Nov 10, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/#comments">13</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/" rel="bookmark">Nov 10, 2009</a></p> <div class="entry"> <p>Fabian asks:</p> <blockquote><p>I’m trying to request data from a website via HTTPS that does not have valid certificate. How can I ignore the certificate error?</p></blockquote> <p>When the iPhone makes a HTTPS request it verifies that the certificate used to encrypt the data has a valid root certificate authority. Usually – for big sites – this is provided by Thawte or Verisign or any other recognized Root Certification Authority (CA). A bundle of the public certificates of such CAs is installed in the OS and enables the client to know which CAs are valid.</p> <p>The problem arises however if you don’t have the funds to purchase such a certificate from a CA, those are expensive. Or sometimes you want to create a certificate for your own use or testing. This is called self-signed certificates. Those are also deemed invalid at first glance, unless you tell your browser to accept these certificates. Or it may be the case of Twitter who seem to have an expired certificate on one of their API servers.</p> <p> <a href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/#more-1488" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/#more-1488">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/11/ignoring-certificate-errors-on-nsurlrequest/#comments" class="button_gray comments">13 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1431" class="post-1431 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/11/detect-roaming/" rel="bookmark">Detect Roaming</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Nov 04, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/11/detect-roaming/#comments">3</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/11/detect-roaming/" rel="bookmark">Nov 04, 2009</a></p> <div class="entry"> <p>hhyyy9 asks:</p> <blockquote><p>It’s possible to detect when device goes on roaming or out of home network and turn on / turn off the data connection?</p></blockquote> <p>Well, yes and no. Yes to the part of the question about detecting. No to changing a system setting.</p> <p>You have no direct access at all to roaming or home network information. Probably via a private framework but Apple does not approve of apps using those. Though you could infer the currently used data network from the IP address range you get from the currently active cellular connection. Each provider will have certain IP ranges and if you collect these ranges then you could build up a database to detect such network switching.</p> <p>Also wheres the point? There already IS a setting that allows you to disable data roaming.</p> <p><a onclick="javascript:pageTracker._trackPageview('/downloads/files/general-network.jpg');" href="http://i1.wp.com/www.cocoanetics.com/files/general-network.jpg"><img class="alignnone size-full wp-image-1432" src="http://i1.wp.com/www.cocoanetics.com/files/general-network.jpg?resize=320%2C480" alt="general network" data-recalc-dims="1" /></a></p> <p>The fact remains that you still cannot mess with the data system setting, but only work within your app.</p> <p>But this would not be an worthy Dr. Touch post if I didn’t share some cool knowledge, this time how you can get all the current IP addresses of your device. Something like “IPCONFIG /ALL” on Windows or “IFCONFIG” on Unix.</p> <p> <a href="http://www.cocoanetics.com/2009/11/detect-roaming/#more-1431" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/11/detect-roaming/#more-1431">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/11/detect-roaming/#comments" class="button_gray comments">3 Comments</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="post-1414" class="post-1414 post type-post status-publish format-standard hentry category-qa"> <h2 class="posttitle"><a href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/" rel="bookmark">Alternating Tableview Cell Backgrounds</a></h2> <!--<p class="postmetadata"><em>by</em> <a href="http://www.cocoanetics.com/author/admin/" title="Posts by admin" rel="author">admin</a> <em>on</em> Oct 30, 2009 <span class="commentcount">(<a href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/#comments">1</a>) Comments</span></p>--> <p class="post_date"><a href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/" rel="bookmark">Oct 30, 2009</a></p> <div class="entry"> <p>Wanner asks:</p> <blockquote><p>“How can I make my cells alternate colors across multiple sections if the sections don’t always have the same number of rows?”</p></blockquote> <p>A nice effect that you sometimes see in table views like the app store app is when you alternate the tableview cell backgrounds between light and dark shades of a color.</p> <p> <a href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/#more-1414" class="more-link">Read more</a></p> <p class="read_more_link"><a class="button_gray" href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/#more-1414">Read more</a></p> <p class="commentlink_container"><a href="http://www.cocoanetics.com/2009/10/alternating-tableview-cell-backgrounds/#comments" class="button_gray comments">1 Comment</a></p> </div><!--/end entry--> </div><!--/end post--> <div id="archive_pagination"> <a href="http://www.cocoanetics.com/category/qa/" class="numbered page-number-first"><span>‹ Newest</span></a> <a href="http://www.cocoanetics.com/category/qa/" class="numbered page-number-1"><span>1</span></a> <a href="http://www.cocoanetics.com/category/qa/page/2/" class="numbered page-number-2"><span>2</span></a> <a href="http://www.cocoanetics.com/category/qa/page/3/" class="numbered page-number-3"><span>3</span></a> <a href="http://www.cocoanetics.com/category/qa/page/4/" class="numbered page-number-4"><span>4</span></a> <span class="numbered page-number-5 current-numeric-page">5</span> <a href="http://www.cocoanetics.com/category/qa/page/6/" class="numbered page-number-6"><span>6</span></a> <a href="http://www.cocoanetics.com/category/qa/page/7/" class="numbered page-number-7"><span>7</span></a> <a href="http://www.cocoanetics.com/category/qa/page/8/" class="numbered page-number-8"><span>8</span></a> <a href="http://www.cocoanetics.com/category/qa/page/8/" class="numbered page-number-last"><span>Oldest ›</span></a> </div> </div><!--/content--> </div> <!--/main--> <div id="copyright_footer"> <div id="copyright_left"> <ul id="register_login_links"> <li><a class="sign_in_link" href="http://www.cocoanetics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.cocoanetics.com%2F2010%2F02%2Fare-you-a-cocoa-crack-quiz-2%2F">Log In</a></li> <li><a class="register_link" href="http://www.cocoanetics.com/wp-login.php?redirect_to=http%3A%2F%2Fwww.cocoanetics.com%2F2010%2F02%2Fare-you-a-cocoa-crack-quiz-2%2F&action=register">Register</a></li> </ul> </div> <div id="copyright_right"> © 2015 <span class="url fn org"> <a href="http://www.drobnik.com/">Drobnik KG</a> </span> </div> </div> </div> </div> <!--/wrapper--> <div id="footer"> <div id="text-4" class="widget widget_text"><h3 class="widgettitle">CC</h3> <div class="textwidget"><p>License:<br /> <a href="http://creativecommons.org/licenses/by-nc-nd/3.0/"><img class="alignleft size-full wp-image-4229" src="/files/cc-image.jpg" alt="" width="88" height="31" /></a></p> </div> </div><div id="text-10" class="widget widget_text"><h3 class="widgettitle">AddThis</h3> <div class="textwidget"><script type="text/javascript"> var addthis_share = { templates: { twitter: '{{title}}: {{url}} via @Cocoanetics' } } </script></div> </div></div> <div id="footer_footer"></div> <!--/footer--> <!-- tracker added by Ultimate Google Analytics plugin v1.6.0: http://www.oratransplant.nl/uga --> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-260144-2"); pageTracker._initData(); pageTracker._trackPageview(); </script> <!-- Advertising Manager v3.5.1 (2.403 seconds.) --> <div style="display:none"> </div> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/photon/photon.js?ver=20130122'></script> <script type='text/javascript' src='http://s0.wp.com/wp-content/js/devicepx-jetpack.js?ver=201536'></script> <script type='text/javascript' src='http://s.gravatar.com/js/gprofiles.js?ver=2015Sepaa'></script> <script type='text/javascript'> /* <![CDATA[ */ var WPGroHo = {"my_hash":""}; /* ]]> */ </script> <script type='text/javascript' src='http://www.cocoanetics.com/wp-content/plugins/jetpack/modules/wpgroho.js?ver=4.2.4'></script> <script type="text/javascript"> (function() { var s = document.createElement('script'), t = document.getElementsByTagName('script')[0]; s.type = 'text/javascript'; s.async = true; s.src = 'http://api.flattr.com/js/0.6/load.js?mode=auto'; t.parentNode.insertBefore(s, t); })(); </script><script type='text/javascript' src='http://stats.wp.com/e-201536.js' async defer></script> <script type='text/javascript'> _stq = window._stq || []; _stq.push([ 'view', {v:'ext',j:'1:3.5',blog:'39982308',post:'0',tz:'2',srv:'www.cocoanetics.com'} ]); _stq.push([ 'clickTrackerInit', '39982308', '0' ]); </script> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery("ul.menu").superfish(); jQuery("#searchfield").attr("value","Search..."); jQuery("#searchfield").focusin(function(){ jQuery("#searchfield").attr("value",""); }); jQuery("#searchfield").focusout(function() { var formvalue = jQuery("#searchfield").attr("value"); if (formvalue=="") { jQuery("#searchfield").attr("value", "Search..."); } }); if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Chrome') == -1) { jQuery('html').addClass('safari_mac'); } }); </script> <script type="text/javascript"> jQuery("li.cat-item a").each(function(){ // Remove Titles from wp_list_categories jQuery(this).removeAttr('title'); }) jQuery("li.page_item a").each(function(){ // Remove Titles from wp_list_pages jQuery(this).removeAttr('title'); }) </script> </body> </html>