Monday, December 14, 2009

ullrich: Optimize your Autorelease pools

Optimize your Autorelease pools with the following environment variables

NSAutoreleaseHighWaterMark
Default: 0
If set to X, autorelease pools will print a message if more than X objects accumulate in the pool

NSAutoreleaseHighWaterResolution
Default: 0
If set to Y, a message is logged for every Y objects that accumulate in the pool beyond the high-water mark (X)

Thursday, December 10, 2009

NSAssert

Vicente Gable:
The NSAssert() function is unreliable, and therefore dangerous. Plain-old assert() is a better choice...

Rob Napier:
Broad use of NSAssert() will not turn ObjC into Eiffel, but it's still a fairly good practice as long as you keep in mind how it's actually implemented and what it's doing. Things to keep in mind about NSAssert():...

Use NSAssert(…) during development.
But set NS_BLOCK_ASSERTIONS pre compiler flag for release.

Tuesday, December 8, 2009

Kamocsay Lajos: how to debug EXC_BAD_ACCESS on iPhone

Itt van az egesz, de roviden a lenyeg:

If you set the NSZombiEnabled environment variable, the Objective C runtime will leave a dummy object behind for every deallocated object. When the zombie object is called, execution stops and you can see the message that was sent to the object and the call stack that tells you where the message came from (it doesn’t tell you where you over released the object, but knowing where the object is called from should get you pretty close to the problem.)

Friday, December 4, 2009

snipplr.com: How to get the actual phone number of the device

src

CFShow([[NSUserDefaults standardUserDefaults] objectForKey:@"SBFormattedPhoneNumber"]);

Monday, November 30, 2009

John Muchow: UIAlertView and Landscape Mode

Itt van az egesz cikk, de a lenyeget idemasolom:

Show Alerts in Landscape Mode

To fix this, all you need to do is add the following line of code – I placed this in the applicationDidFinishLaunching method:

// Required so UIAlertView shows in the correct orientation in landscape mode

[application setStatusBarOrientation:

UIInterfaceOrientationLandscapeRight animated:NO];


Thursday, November 26, 2009

MPSwipableView, MPFullScreenVideoOverlay

Amikor az MPMoviePlayerController csinal egy sajat window-t ami a keyWindow lesz, akkor ennek egy subView-ja van es az egy MPSwipableView amirol nem talaltam sok mindent, csak annyit, hogy UIView-bol oroklodott es az MPFullScreenVideoOverlay az o leszarmazottja, de ezek nem dokumentalt view-k.

Tuesday, November 24, 2009

MPMoviePlayerController Done button-janak letakarasa.

Eloszor is az [MPMoviePlayerController Play] csinal egy sajat window-t, tehat a UIButton-t amivel le fogjuk takarni a Done buttont azt a keyWindowChanged notification-ben kell letrehozni.

Azt gondolnank, hogy egy akkora gombot kell rarakni mint amekkoranak ot latjuk, de valojaban a minimalis biztos megoldas ha a UIButton frame-je (256, 5, 43, 49)-es frame lesz. Ez igy fog kinezni ha lathatova tesszuk:

Meg kozelebbrol igy nez ki:
Lathato, hogy a szurke sav tetjebol igy nincsen letarkva egy pixelnyi ami mar nem baj, de ha egy pixellel alacsonyabb lenne a takaras, akkor mar valahova C betu aljara bokve megkapna a Done button az event-et.
Eleg furcsa igy ez a (256, 5, 43, 49) CGRect. Szebb lenne mondjuk egy (255, 5, 45, 50)-es, ami szinten jo. A lenyeg, hogy a (256, 5) es a (299, 54) pontok es az alltaluk hatarolt resz le legyen takarva. Legalabbis 3.1.2-es OS-nel igy lehet letararni a Done button-t.
Erdekes egyebkent, hogy ha nincsn letakrava akkor nyugodtan lehet mondjuk a Carrier feliratot is nyomni a Done button folott ugy is megkapja a Done button az eventet, ugyanakkor nem kell odaig letakarni. Nem tudom hogy van ez a gomboknal, de nagyon ugy tunik, hogy nem pont azt a reszt fedik le ami latszik beloluk, hanem valamivel tobbet.

Friday, November 20, 2009

overlay View az MPMoviePlayerController-en

Az [MPMoviePlayerController play] utan csinal egy sajat window-t ami a sharedApplication keyWindow-ja lesz, azaz ezen kell meghvini az addSubview-t, viszont fontos, hogy megvarjuk mire valoban ez lesz a keyWindow. Ezt ugy tehetjuk meg, hogy a play elott feliratkozunk a UIWindowDidBecomeKeyNotification notification-re es abban adjuk hozza a sajat UIView-(i)nkat a keyWindow-hoz (ami a [notfication object]).

Wednesday, November 18, 2009

awakeFromNib

Inkabb bemasolom ide az egeszet:

Prepares the receiver for service after it has been loaded from an Interface Builder archive, or nib file.

- (void)awakeFromNib

Discussion

The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized. When an object receives an awakeFromNib message, it is guaranteed to have all its outlet and action connections already established.

You must call the super implementation of awakeFromNib to give parent classes the opportunity to perform any additional initialization they require. Although the default implementation of this method does nothing, many UIKit classes provide non-empty implementations. You may call the super implementation at any point during your own awakeFromNib method.

Note: During Interface Builder’s test mode, this message is also sent to objects instantiated from loaded Interface Builder plug-ins. Because plug-ins link against the framework containing the object definition code, Interface Builder is able to call their awakeFromNib method when present. The same is not true for custom objects that you create for your Xcode projects. Interface Builder knows only about the defined outlets and actions of those objects; it does not have access to the actual code for them.

During the instantiation process, each object in the archive is unarchived and then initialized with the method befitting its type. Objects that conform to the NSCoding protocol (including all subclasses of UIView and UIViewController) are initialized using their initWithCoder: method. All objects that do not conform to the NSCoding protocol are initialized using their initmethod. After all objects have been instantiated and initialized, the nib-loading code reestablishes the outlet and action connections for all of those objects. It then calls the awakeFromNibmethod of the objects. For more detailed information about the steps followed during the nib-loading process, see Nib Files and Cocoa in Resource Programming Guide.

Important: Because the order in which objects are instantiated from an archive is not guaranteed, your initialization methods should not send messages to other objects in the hierarchy. Messages to other objects can be sent safely from within an awakeFromNib method.

Typically, you implement awakeFromNib for objects that require additional set up that cannot be done at design time. For example, you might use this method to customize the default configuration of any controls to match user preferences or the values in other controls. You might also use it to restore individual controls to some previous state of your application.


networkActivityIndicatorVisible

A UIApplication class-ban van.

A Boolean value that turns an indicator of network activity on or off.

Hogyan merjuk az eltelt idot

Aaron Hillegass: How to Time

#import 

uint64_t start = mach_absolute_time();

// do stuff to be timed

uint64_t end = mach_absolute_time();
uint64_t elapsed = end - start;

mach_timebase_info_data_t info;
if (mach_timebase_info (&info) != KERN_SUCCESS) {
    printf ("mach_timebase_info failed\n");
}

uint64_t nanosecs = elapsed * info.numer / info.denom;
uint64_t millisecs = nanosecs / 1000000;

Tuesday, November 17, 2009

Status bar eltuntetese

Az Interface Builder-ben hiaba allitjuk none-ra a Status Bar-t (320 x 20 px), az attol meg latszik.

Igy kell eltuntetni:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];


Ez viszont onmagaban meg nem eleg, mert a View teteje ugyan felkerul a Status bar helyere, de letakarja egy darab a Root View Controllerbol. Akkor mukodik jol, ha az xx-Info.plist-ben felvesszuk a "Status bar is initally hidden" kulcsot es kipipaljuk. Ezutan persze ahol latni szeretnenk a Status bart, ott kulon meg kell adni a fenti hivassal, hogy NE legyen hidden, de ahol azt adjuk meg, hogy legyen hidden ott tenyleg az lesz.

A masik lehetoseg, ha nem nyulunk az Info.plist-hez, hanem az AppDelegate-ben az applicationDidFinishLaunching-ban allitjuk be YES-re mielott a window-hoz hozzaadnank a Sub View-t. Ezutan akar vissza is allithatjuk NO-ra es csak ott valtoztatunk rajta ahol kell.

A lenyeg, hogy miutan egy Sub View-t mar hozzaadtunk a window-hoz, akkor mar hiaba rejtjuk el a Status Bar-t, ha elotte nem tettuk meg akkor hibas lesz. Ez valami bug lehet, a 3.1.2-ben amit gondolom kesobb majd javitanak.

Wednesday, November 11, 2009

Thumbnail keszitese

Itt van egy fuggveny ami csinal egy thumbnailt egy UIImage-hez anelkul, hogy torzitana. Ha a thumbnail meretaranya kulonbozik az eredeti kepetol, akkor levag a tetejebol-aljabol vagy az oldalaibol.

Categories

Ahogy John Muchow irja:
"As an alternative to subclassing, Objective-C categories provide a means to add methods to a class. What’s intriguing, is that any methods that you add through a category become part of the class definition, so to speak. In other words, if you add a method to the NSString class, any instance, or subclass, of NSString will have access to that method.

Defining a category is identical to defining the interface for a class, with one small exception: you add a category name inside a set of parenthesis after the interface declaration..."

Categories and Extensions leiras az iPhone OS Reference Libraryban

Monday, November 9, 2009

Milyen warningokat erdemes bekapcsolni

Peter Hosey irasa.

Sunday, November 8, 2009

How To Get two or more different versions of the same app on your iphone.

via Google Groups

1. Right click on the project
2. Select Get Info menu
3. Find Product Name in the right column
4. Change this property as you like. E.g. build20091107
5. Build your app
6. Upload app on the iphone
7. Get the icon with the text build20091107
8. Go ahead and repeat all steps once again but set another build
number in the step 4. E.g. build20091108
9. Get two different apps on your iphone.

Thursday, November 5, 2009

UIActionSheet

A dokumetacio es egy rovid tutorial.

Monday, November 2, 2009

Button (vagy barmi mas) UITableView ala

Ugy szerettem volna gombokat elhelyezni egy UITableView ala, hogy azok egyutt scrollozzanak. Erre itt van egy megoldas: A tableView:viewForFooterInSection-ben kell visszaadni egy olyan UIView-t amiben letrehozunk egy UIButton-t, vagy amit szeretnenk. Fontos, hogy a tableView:heightForFooterInSection-ben olyan magassagot allitsunk be, amibe belefer majd a UIView-nk. Azt nem emlitik, de fontos lehet, hogy a tableView:viewForFooterInSection a UITableViewDelegate-ben van.
Ez meg itt egy masik pelda ugyenrre, csak UIButton helyett UISwitch.

Update: Multkor fejbol csinaltam es elfelejtettem, a tableView:heightForFooterInSection-t beallitani. Enelkul is lattam a footer view-ba pakolt gombokat, csak megnyomni nem lehetett oket.

Thursday, October 29, 2009

Cell Styles

Ilyenek vannak:

UITableViewCellStyleDefault

A simple style for a cell with a text label (black and left-aligned) and an optional image view. Note that this is the default style for cells prior to iPhone OS 3.0.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleValue1

A style for a cell with a label on the left side of the cell with left-aligned and black text; on the right side is a label that has smaller blue text and is right-aligned. The Settings application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleValue2

A style for a cell with a label on the left side of the cell with text that is right-aligned and blue; on the right side of the cell is another label with smaller text that is left-aligned and black. The Phone/Contacts application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

UITableViewCellStyleSubtitle

A style for a cell with a left-aligned label across the top and a left-aligned label below it in smaller gray text. The iPod application uses cells in this style.

Available in iPhone OS 3.0 and later.

Declared in UITableViewCell.h.

Discussion

In all these cell styles, the larger of the text labels is accessed via the textLabel property and the smaller via the detailTextLabel property.

App Version

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

Thursday, October 15, 2009

SubString keresese NSString-ben

Mondjuk a @-ot igy talaljuk meg egy email cimben:

NSString *s = @"jdoe@example.com";

NSRange range = [s rangeOfString:@"@"];

Az NSRange-nek van egy location-je es egy length-je.
Ha a location NSNotFound, akkor egyet sem talalt:
If (NSNotFound == range.location) {...}
Ha pedig megtalalta, akkor akkor a location a kereset substring elso karakterenek pozicioja a string-ben.

Monday, October 12, 2009

Honnan lehet tudni, hogy Simulator-ban fut-e az app

Valasz a stackoverflow-rol:

It's in the SDK docs under "Compiling source code conditionally"

The relevant definitions are TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR, which will be defined provided that you

#include "TargetConditionals.h"

Since that won't exist on non apple platforms, you can wrap your include like this

#ifdef __APPLE__
#include "TargetConditionals.h"
#endif

before including that file

So, for example, if you want to check that you are running on device, you should do

#if !(TARGET_IPHONE_SIMULATOR)

Itt is felmerult ugyanez a kerdes. Es itt van az iPhone Reference Library-ban.

Thursday, October 8, 2009

GUID generalasa iPhone-on

Felmerult ez a kerdes a stackoverflow-n is, ahol a CFUUID object-et ajanlottak illetve ezt a kodreszletet:

+ (NSString *)GetUUID
{
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
return [(NSString *)string autorelease];
}

Friday, October 2, 2009

Fast Enumeration

Itt azt irjak, hogy a Fast Enumeration gyorsabb es tomorebb mint az NSEnumerator.

Tuesday, September 22, 2009

Fenyes gombok keszitese

Itt van egy cikksorozat Michael Heyecktol arrol, hogyan lehet szep fenyes gombokat kesziteni a szokasos UIButton helyett.

Tuesday, September 15, 2009

Andy Finnell: Don’t lose your keys

Leirja, hogy milyen fontos a private key elmentese es hogyan kell csinalni.

Andy Finnell: [UIImage imageNamed:] is a memory leak

Itt van az egesz, de a lenyeg roviden:

"... the UIImages I had constructed with imageNamed: were failing to be released. I suspected that they were being retained in a global cache. The only problem with this cache is it is never released, ever. Even when my app receives a low memory notification and I free up all the memory I can, the UIImage global cache just sits there clutching it’s unused UIImages to its chest, muttering."
...
"The moral of the story is imageNamed: is only for use with small images that are used constantly throughout the app’s lifetime. Never use imageNamed: if you ever want that memory back."

Monday, September 7, 2009

Core Data save hiba es NSError Array (1560) kiiratasa

NSManagedObject save metodusa hibat adott amibol nem tudtam meg tul sokat (Operation could not be completed. (Cocoa error 1560.)), de a Stackowerflow-n segitettek:

Eloszor is valamelyik mandatory property-nek nem adtam erteket.

Masodszor pedig azt is megtudtam, hogy nem csak egy sima NSError-t kaptam vissza, hamem egy NSError tombot (ezt jelenti az 1560). Rendesen kiiratni meg igy kell.

UIImage betoltese bundle-bol

Idezve a The Geek Blog-ot:

[UIImage imageWithContentsOfFile:

[[NSBundle mainBundle]

pathForResource:@"thefilename"

ofType:@"jpg"]];

Glyphysh - 120 icons for iPhone applications

Itt van. (Creatitve Commons Attribute licencelt)

UIImage trukkok

Eloszor is kellett egy thumbnail-t kesziteni egy jpg-bol amihez innen szedtem az otletet es igy csinaltam meg:

NSData *imageData = [[NSData alloc] initWithContentsOfFile:filePath];

UIImage *img = [[UIImage alloc] initWithData:imageData];


UIGraphicsBeginImageContext(CGSizeMake(75.0,75.0));

[img drawInRect:CGRectMake(0.0, 0.0, 75.0, 75.0)];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData *thumbData = UIImageJPEGRepresentation(newImage, 0.5);

[thumbData writeToFile:thumbPath atomically:YES];




Aztan itt vannak meg a kovetkezo dolgok:
  • Combine 2 UIImages
  • Create a UIImage from a part of another UIImage
  • Save UIImage to Photo Album

Thursday, September 3, 2009

UITableViewCell beszurasa UITableView-ba

Igy szurunk be egy cellat a TableView elejere:

[self.tableView insertRowsAtIndexPaths:myObject withRowAnimation:UITableViewRowAnimationFade];


Igy pedig feltekerunk, hogy lassuk az uj cellat:

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];


Wednesday, September 2, 2009

Locating Directories on the System

Igy kell csinalni.

Saturday, August 29, 2009

UIActivityIndicatorView

Igy hivjak a forgo kis kurzort es itt van rola a leiras.

Fontos, hogy a hidesWhenStopped property default YES, tehat ha nem inditjuk el a porgest a startAnimating-gal es nem allitjuk be a hidesWhenStopped-et NO-ra akkor hiaba pakoljuk ki valahova a View-t, nem fogjuk latni.

Tuesday, August 25, 2009

App Icon keszitese

Itt van egy leiras Dustin Yonak-tol.

Monday, August 24, 2009

Hogyan futtassunk az app-unkat iPhone-on, ha mar megvan a licence

A DevClinic-en szepen leirjak.

Publishing Applications for Testing

Itt minden szepen le van irva.

Kepek leszedese iPhone-rol

Az Image Capture megoldja es van egy Cameras nevu plugin ami megkonnyiti a dolgot:

With familiar System Preference functionality, Cameras allows you to manage what happens when you connect your:

  • Digital camera
  • iPhone
  • Digital media reader
  • Any photo device

In addition to launching a specific application when you connect a camera, you can also have your images download automatically. Never again spend time launching the right app or quitting apps that you didn't want to launch.


Friday, August 14, 2009

Maximum hossz beallitas UITextField-ben es UITextView-ban

Itt van egy leiras, de a lenyeg:
  • A View implementalja aUITextViewDelegate vagy UITextFieldDelegate protokollt.
  • UITextView eseten a textView:shouldChangeTextInRange:replacementText method-ban, UITextField eseten pedig a textField:shouldChangeCharactersInRange:replacementString method-ba kell tenni az ellenorzest
Azt kell megnezni, hogy [[textView text] length] > 0 es
range.length == 0
(range.length 1 lesz, ha torlok egy karaktert)
Illetve UITextField eseten textView helyett textField es range helyett string.

Azt nem tudom, hogy ez mukodik-e igy paste-nel is, mert azt meg nem sikerult kiprobalni a Simulatorban.

Nick Dalton: How To Create A Data Entry Screen

Itt van.

Wednesday, August 12, 2009

thumbnail betoltese UITableViewCell-be

Kell egy custom UITableViewCell aminek van egy UIImageView propertyje
pl.:

IBOutlet UIImageView *image;

...

@property (nonatomic, retain) IBOutlet UIImageView *image;


Es ebbe igy lehet betolteni egy kepet file-bol, ha tudjuk hol van:

NSString *filePath = ...;


[[cell image] setImage:[[UIImage alloc] initWithContentsOfFile:filePath]];