Archive for 'iPhone'

View Controller memory

Here’s a tip to take to heart for your didReceiveMemoryWarning implementations in your view controllers: stash the superview before calling [super didReceiveMemoryWarning] so you don’t immediately recreate it.

[EDIT: Apparently our commenters are more clued in than both us and the original tipster. Your view controllers will get didReceiveMemoryWarning even if their view hasn't been loaded yet ... which means that if you follow this tip, the first thing you'll do is load the view. That is not a sensible response to low memory conditions. Therefore, you should check that your views have indeed been loaded!]

So, a really defensive implementation would look like this:

 

- (BOOL)viewIsLoaded
{
   return nil != _sharedPlayer; // or whatever viewDidLoad setup you can test
}

- (void)didReceiveMemoryWarning
{
   if (![self viewIsLoaded])
      return;

    UIView* superview = self.view.superview;

    // Releases the view if it doesn't have a superview
    [super didReceiveMemoryWarning];

    if ( superview == nil )
    {
        // OK. NOW we can assume view is gone.
    }

     // Destroy any caches regardless here
}

This is for the good of people who have their own memory issues, of course, not people who have imageNamed kill the system behind their back. Which isn’t us, yet. But some day it might be!

h/t: iPhoneKicks!

Continue Reading →
2

Multiple OpenGL UIViews

Here’s a tip you definitely need to give a read if you’re of the common opinion that OpenGL is only appropriate for fullscreen applications like games: how to not only integrate OpenGL views with UIKit nicely, but use multiple OpenGL views!

Things get more complicated when you want to have multiple views with OpenGL rendering. I don’t mean multiple viewports in the same screen, but multiple views in the sense of multiple UIViews. My current project, for example, has different views connected with a UITabBarController. Some of the are custom UIViews and some of them are OpenGL views.

My first thought was to try to have different OpenGL contexts for each view, but that would complicate things because I wanted to share the same textures and other resources. I know there’s a shared groups option, but that was definitely not the way to go.

The best solution I found was to use multiple frame buffers, binding each of them to the correct OpenGL view. That way, when I switch views, I switch frame buffers and everything works correctly.

Simple once you know how, isn’t it?

h/t: iPhoneKicks!

Continue Reading →
0

SQLite Resources

So maybe you’ve been thinking it’d be a good idea to get a leg up on SQLite, since it’s the data management technology of choice on the iPhone and all. Here’s a roundup of resources for you!

For starters, here is an excellent introductory tutorial to SQLite in general:

This article explores the power and simplicity of sqlite3, starting with common commands and triggers. It then covers the attach statement with the union operation, introduced in a way that allows multiple tables, in separate databases, to be combined as one virtual table, without the overhead of copying or moving data. Next, I demonstrate the simple sign function and the amazingly powerful trick of using this function in SQL select statements to solve complex queries with a single pass through the data…

Then, we have a walkthrough tutorial demonstrtating its use with the iPhone SDK:

I see many people asking for SQLite tutorials around, and since I am using SQLite for the next part in the Advanced RSS Reader Tutorial, I thought I would write up a quick tutorial on using SQLite with the iPhone SDK…

And when you want an embeddable library for your desktop and iPhone work, from those Plausible guys we keep mentioning, here’s pldatabase at Google Code:

A SQL database access library for Objective-C, initially focused on SQLite as an application database. The library supports both Mac OS X and iPhone development.

Plausible Database is provided free of charge under the BSD license, and may be freely integrated with any application.

… and if you’re looking for more, more, MORE, here’s a list put together by the guys over at MobileOrchard!

12 SQLite Resources for iPhone Developers

Continue Reading →
2

Library: PLCrashReporter

Here’s another even more useful open source library from those great guys at PlausibleLabs who did the ActorKit project we mentioned before; PLCrashReporter, a crash reporting framework you can use on the desktop, in the simulator, and on the device:

Plausible CrashReporter provides an in-process crash reporting framework for use on both the iPhone and Mac OS X.

Crash reports are output as protobuf-encoded messages, and may be decoded using the CrashReporter library or any Google Protobuf decoder.

The CrashReporter library handles both uncaught exceptions and fatal signals.

Features:

  • Implemented as a in-process fully async-safe signal handler.
  • Does not interfere with debugging in gdb
  • Handles both uncaught Objective-C exceptions and fatal signals (SIGSEGV, SIGBUS, etc)
  • Backtraces for all active threads are provided.
  • Provides full register state for the crashed thread.

Is that awesome, or what? We’ve worked with a few of these kinds of frameworks before, but this looks rather better than any of them, even leaving aside the whole works on the phone thing. Definitely going to stick this into all our projects just as soon as we have a minute. Read about it here, download the code here!

h/t: iphonesdk!

Continue Reading →
3

NSDateFormatter formatting

Ever wonder just what you could put in NSDateFormatter format strings? Enough to actually go to the trouble of actually dumping specifiers and results? Nah, us neither. But somebody did, and here’s what they found:

a: AM/PM
A: 0~86399999 (Millisecond of Day)
 
c/cc: 1~7 (Day of Week)
ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat
cccc: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
 
d: 1~31 (0 padded Day of Month)
D: 1~366 (0 padded Day of Year)
 
e: 1~7 (0 padded Day of Week)
E~EEE: Sun/Mon/Tue/Wed/Thu/Fri/Sat
EEEE: Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday
 
F: 1~5 (0 padded Week of Month, first day of week = Monday)
 
g: Julian Day Number (number of days since 4713 BC January 1)
G~GGG: BC/AD (Era Designator Abbreviated)
GGGG: Before Christ/Anno Domini
 
h: 1~12 (0 padded Hour (12hr))
H: 0~23 (0 padded Hour (24hr))
 
k: 1~24 (0 padded Hour (24hr)
K: 0~11 (0 padded Hour (12hr))
 
L/LL: 1~12 (0 padded Month)
LLL: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec
LLLL: January/February/March/April/May/June/July/August/September/October/November/December
 
m: 0~59 (0 padded Minute)
M/MM: 1~12 (0 padded Month)
MMM: Jan/Feb/Mar/Apr/May/Jun/Jul/Aug/Sep/Oct/Nov/Dec
MMMM: January/February/March/April/May/June/July/August/September/October/November/December
 
q/qq: 1~4 (0 padded Quarter)
qqq: Q1/Q2/Q3/Q4
qqqq: 1st quarter/2nd quarter/3rd quarter/4th quarter
Q/QQ: 1~4 (0 padded Quarter)
QQQ: Q1/Q2/Q3/Q4
QQQQ: 1st quarter/2nd quarter/3rd quarter/4th quarter
 
s: 0~59 (0 padded Second)
S: (rounded Sub-Second)
 
u: (0 padded Year)
 
v~vvv: (General GMT Timezone Abbreviation)
vvvv: (General GMT Timezone Name)
 
w: 1~53 (0 padded Week of Year, 1st day of week = Sunday, NB: 1st week of year starts from the last Sunday of last year)
W: 1~5 (0 padded Week of Month, 1st day of week = Sunday)
 
y/yyyy: (Full Year)
yy/yyy: (2 Digits Year)
Y/YYYY: (Full Year, starting from the Sunday of the 1st week of year)
YY/YYY: (2 Digits Year, starting from the Sunday of the 1st week of year)
 
z~zzz: (Specific GMT Timezone Abbreviation)
zzzz: (Specific GMT Timezone Name)
Z: +0000 (RFC 822 Timezone)

What, their word not good enough for you? You want an iPhone program to test it out for yourself? Well, here you can download that too. That should settle your date and time formatting needs once and for all!

Continue Reading →
11

Code: UITableView multiple selection

My, we do seem to be writing a lot about UITableView recently, don’t we? But this is a particularly good one — how to implement multiple-row selection and actions:

UITableView does not support multiple selection. We will use the method tableView:didSelectRowAtIndexPath: to detect touches in rows but the selected state will need to be stored separately (we cannot rely on the UITableView‘s selection).

We will also need a background view for displaying the selection color and a UIImageView for displaying the not-selected/selected indicator. Since the UIImageView will be hidden while not editing and the label for the row needs to move left or right when it is shown or hidden, we will also need to implement some form of layout for the UITableViewCell.

Other required behaviors include switching the “Edit”/”Cancel” buttons between modes, showing/hiding the toolbar at the bottom and tracking the number of selected rows to display in the button in the toolbar…

Mighty handy stuff, that. Code can be downloaded here. And from quickly flipping around, looks like the entire CocoaWithLove blog this comes from is worth your perusal, there’s quite a number of nifty pieces of esoterica therein.

h/t: iPhoneKicks!

Continue Reading →
0

Selection FAIL

Hey, looks like we’ve starting a continuing series of FAIL for your amusement and edification. Today’s exhibit is the proper selection behavior of your UITableView. Specifically,

Your application cannot be submitted to the App Store because of a Table View issue. Applications must adhere to the iPhone Human Interface Guidelines as outlined in iPhone SDK Agreement section 3.3.5.

According to the Table Views, Text Views, and Web Views section of the iPhone Human Interface Guidelines:

“Table views provide feedback when users select list items. Specifically, when an item can be selected, the row containing the item highlights briefly when a user selects it to show that the selection has been received. Then, an immediate action occurs: Either a new view is revealed or the row displays a checkmark to indicate that the item has been selected. The row never remains highlighted, because table views do not display persistent selected state.”

In your application, tapping on an item in the Table View results in the item becoming highlighted, and a new view is displayed. However, upon returning to the Table View, the item remains highlighted. Once the action has occurred, the Table View should no longer be highlighted when the user returns.

In order for your application to be reconsidered for the App Store, please resolve this issue and upload your new binary to iTunes Connect.

Sheesh. Somehow, we had completely managed to miss that there needed to be some active intervention there, we’d just kinda assumed that normal behavior would get taken care of by default. Ah, assumptions.

So, in case you happen to be submitting your first UITableView selecting app, here’s what we did to sort this out. In the appropriate UIViewController class, override:

// deselect selected row if any -- otherwise we GET REJECTED!
- (void)viewWillAppear:(BOOL)animated
{
   (void)animated;

   NSIndexPath *selection = [self.libraryTableView indexPathForSelectedRow];
   if (selection)
   [self.libraryTableView deselectRowAtIndexPath:selection animated:YES];
}

… and then we display the same animating out the selection when returning behavior that the iPod app for instance does. We trust that’s correct behavior.

Continue Reading →
2

Icon FAIL

Well, here’s a reason we hadn’t run into before for Apple to toss your app into the FAIL bucket:

Your application cannot be submitted to the App Store because it uses a standard “Camera” button for an action which is not its intended purpose. Applications must adhere to the iPhone Human Interface Guidelines as outlined in iPhone SDK Agreement section 3.3.5.

The “Camera” button is to be used to opens an action sheet that displays a photo picker in camera mode. Implementing standard buttons to perform other tasks will lead to user confusion. We recommend using Custom button.

In order for your application to be reconsidered for the App Store, please resolve this issue and upload your new binary to iTunes Connect.

That’s rather annoying, as we’d actually gone to some trouble to find that icon in a UITabBar-usable form specifically because that tab does display a photo picker in camera mode … once you’ve picked and positioned an overlay. Apparently Apple thinks users are very easily confused if that little diversion is too much for them.

Ah well. Live and learn. Hey, it could be worse, they could have actually found some problem with the code…

Continue Reading →
3

Code: Searching UITableView

Over at iPhoneSDKArticles.com they’ve been running a series on how to work with UITableView. The latest one is definitely worth your attention; it goes into step by step detail on how to manage the entire experience of allowing the user to refine the list with a search field.

When the user begins searching by clicking the search text box, we will do the following:

  1. Set the “searching” variable to YES.
  2. Set the “letUserSelectRow” variable to NO, since we do not want the user to select a row when the search box is empty.
  3. Display a done button on the right bar.
  4. Start searching as the user starts typing, this time allowing the user to select a row.
  5. Use a different data source to bind the table, which display’s the search reults.
  6. Search results are displayed in a single list and they are not grouped.
  7. Hide the keyboard and finish searching, when the user clicks on done.

Source code link doesn’t seem to be working for us at the moment … but most of it’s in the article anyways, and the missing bits can’t be hard to fill in, we’re sure.

h/t: iPhoneKicks!

Continue Reading →
3

Class: WAImageDropShadowEffect

Here’s a nifty curved drop shadow border for presenting an image with:

dropshadow

and here is the Core Graphics code to produce that effect, Open Source courtesy of the nice folks at WideAsleep, who you might remember from our very last post about their postmortem on application design of their Fairway application, which we looked at again but is apparently still something to do with golf. That aside, it looks like their blog is probably a good one to keep tabs on!

h/t: iPhoneKicks!

Continue Reading →
1
Page 80 of 92 «...5060707879808182...»