Tuesday, March 30, 2010

Igy kell megkeresni az NSDocumentDirectory-t

innen

Locating Directories as Paths

The following example illustrates how you can use the NSSearchPathForDirectoriesInDomains function to find the current user’s Documents directory:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) {
    NSString *userDocumentsPath = [paths objectAtIndex:0];
    // Implementation continues...

NSSearchPathForDirectoriesInDomains simply returns the path of the appropriate directory, it does not guarantee that the directory exists. If you want to perform operations such as writing to the directory, you may have to create it first.

Monday, March 29, 2010

Refresh UITableView UIActivityIndicatorView hasznalataval

Olyasmit akartam csinalni, mint a Mail app-ban, hogy egy refresh gomb megnyomasara elkezdporogni az UIActivityIndicatorView a toolbarban, majd amikor sikerult frissiteni a szerverrol akkor visszakerul a refresh gomb. (A Mail app-ban nem tunik el a refresh gomb, de nalam igen.)

A UIViewController toolBarItems-e egy NSArray amiben a UIView-k vannak. Ugy lehet ezeket egymastol egyenlo tavolsagra tenni, ha beteszunk kozejuk olyan UIBarButtonItem-eket amiket UIBarButtonSystemFlexibleSpace-kent inicializalunk.

Elsore ugy probaltam, hogy refreshButton push-aba akartam meghivni egymas utana toolbar atvaltoztatasat, a szerverrol valo adatlekerest es a toolbar visszavaltoztatasat, ami azert se volt jo megoldas, mert ez leblokkolta volna az alkalmazast es azert sem, mert igy nem valtozott a toobar sem. Ehelyett megvaltoztatom a toolbart es egy masik thread-ben kommunikalok a szerverrel majd frissitem a tableview-t es a toolbart.


DryIcons.com - ingyenes ikonok

Itt.

Icon mellett lathato kis szam (badgeNumber) beallitasa

[[UIApplication sharedApplication] setApplicationIconBandgeNumber:42];

Tuesday, March 2, 2010

UIBarButtonItem title-jenek beallitasa

Ha a initWithBarButtonSystemItem:target:action:-nel inicializaljuk a UIBarButtonItem-et, akkor utana a setTitle nem valtoztatja meg a title-jet, ezert inkabb a initWithTitle:style:target:action:-t kell hasznalni.

Monday, March 1, 2010

NSDate to NSString

Az NSDateFormatter segitsegevel igy:

NSDate *now = [NSDate date];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

[dateFormat setDateStyle:NSDateFormatterFullStyle];

NSString *s = [dateFormat stringFromDate:now];

[dateFormat release];

Persze ha a setDateStyle helyett a setDateFormat-ot hasznajuk akkor a Date Formatter lehet sokfele, peldaul:
"MM.dd.yyyy. hh:mm" > "03.01.2010"
"MM/dd/yyyy hh:mma" > "03/01/2010 04:20PM"
Vagy a setDateStyle-nal maradva az NSDateFormatterStyle-bol hasznalhatjuk barmelyiket.

Monday, February 22, 2010

The UIImagePickerController class supports portrait mode only.

Ahogy a dokumentacioban is all:

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. In iPhone OS 3.1 and later, you can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

Wednesday, February 17, 2010

Hol vannak a provisioning profile-ok a gepen.

On OSX /Users/username/Library/MobileDevice
On XP C:/Documents and Settings/username/Application Data/Apple Computer/MobileDevice/
On Vista C:/Users/username/AppData/Roaming/Apple Computer/MobileDevice/

Tuesday, February 16, 2010

NSString to NSURL

Eloszor:
- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
Utana:
+ (id)URLWithString:(NSString *)URLString

Monday, January 18, 2010

UIView class-anak ellenorzese

Ha egy public class-rol van szo (pl UILabel) akkor konnyu megnezni:

if ([myView isKindOfClass:[UILabel class]]{

NSLog(@"myView is a UILabel");

}

de ha egy private class-ra akarom ellenorizni (pl MPFullScreenTransportControls) akkor az igy mar le sem fordulna. Ilyenkor ez is egy lehetseges megoldas:

NSString *className = NSStringFromClass([myView class]);

if (NSOrderedSame == [className compare:@"MPFullScreenTransportControls"]) {

//...

}

NSArray bejarasa "foreach"

for(id myArrayElement in myArray) {

//do something with myArrayElement

}


Friday, January 15, 2010

MPMoviePlayerController vezerlese - megoldas

Tovabbra is az a lenyeg, hogy MPMoviePlayerController-rel le tudjak jatszani egymas utan tobb movie-t es a "previous" "next" gombokkal tudjak valtogatni kozottuk valamint a Done gombra alljon le.

Volt tobb rosz megoldasom:
-megneztem, hogy MPMoviePlayerPlaybackDidFinishNotification-ben meg tudom-e allapitan miert lett vege, de erre a 3.1.2-ben nincs lehetoseg (ugyanugy kuldi a notification-t, ha vege van a movie-nak, vagy ha a megnyomta a user a done, "prev", "next" gombok valamelyiket)
-Probaltam atlatszo UIButton-okkal letakarni ezeket a gombokat es a sajat gombjaim megnyomasat lekezelni, de ez sem jo, mert a default controlok eltunnek/megjelennek es errol sincsen semmi ertesites.
-Felmerult, hogy csupa sajat UIView-val megcsinalni, ami egyreszt nem lett volna tul szep, masreszt a timeline es a volume control gondot okozott volna.

Vegul ezt a megoldast talaltam (ami egyreszt nem menne at valoszinuleg az app store-on, masreszt a kovetkezo SDK-val valtozhat is. 3.1.2-vel probaltam):

Tovabbra is felteszem az osszes controlt az MPMoviePlayerController-re (MPMovieControlModeDefault), majd igy ferek hozzajuk a UIWindowDidBecomeKeyNotification-ra feliratkozva. (Eloszor a MPMoviePlayerContentPreloadDidFinishNotification-t akartam hasznalni, de az nem volt jo. Elsore ezt nem is vettem eszre, mert az elso movie betoltesenel eloszor a keyWindow notificaton jott meg es utana a preloadDidFinish, viszont a masodik play-nel mar forditva.):

id internal;

object_getInstanceVariable(player, "_internal", (void *)&internal);

id videoViewController;

object_getInstanceVariable(internal, "_videoViewController", (void*)&videoViewController);

UIView *overlayView = [videoViewController _overlayView]; //MPFullScreenVideoOverlay


Ennek a UIView-nak pedig a subview-it siman le lehet kerni amik nagyjabol igy neznek ki. Azert nagyjabol, mert subviews egy NSArray-t ad vissza amiben az elemek sorrendje nem kotott. Azt figyeltem meg, hogy az MPFullScreenVideoOverlay-nek ha lekerem a subview-it akkor az mindig ugyanabban a sorrendben jott vissza /MPFullScreenTransportControls, NPCenteringNavigationBar/ es meg az MPFullScreenTransportControls subview-it lekerve is ugyanaz volt a sorrend /play, next, previous/, de az NPCenteringNavigationBar-nal az elso video betoltesenel UINavigationButton, UIView volt a sorrend, de a masodiknal mar pont forditva. Tehat ha subview-kat kerunk le egy NSArray-ba, akkor ne hagyatkozzunk a sorrendre, mert nem mi raktuk ossze!!!

Tehat ha igy a kezunkben van peldaul a "next" gomb, akkor arra ra is kothetjuk a sajat targetaction-unket a UIControlEventTouchUpInside-ra. Nem art elott lekotni rola a defult action-t:

[nextButton removeTarget:fstc action:nil forControlEvents:UIControlEventTouchUpInside];

[nextButton addTarget:self action:@selector(nextButtonClicked:) forControlEvents:UIControlEventTouchUpInside];


Aztan persze meg kell irni a sajat nextButtonClicked methodunkat is (meg a tobbi gombet is) amiben ha van meg lejatszando movie-nk akkor release-eljuk az MPMoviePlayerController-t majd csinalunk egy ujat a kovetkezo movie-val.>

Wednesday, January 6, 2010

MPMoviePlayerController "Previous" es "Next" button-jainak letakarasa.

Amig nem talalok megoldast ez elozo problemara, addig ugyanugy letakarom 1-1 UIButton View-val a "previous" es "next" (nem tudom mi a hivatalos nevuk) buttont, mint ahogy a Done buttonnal tettem, a minimalis CGRect pedig amivel le lehet takarni az a (36, 122, 63, 71) es a (36, 287, 63, 71) azaz a (36,122) es (99, 193) illetve a (36, 287) es (99, 358) kozotti terulet.
Igy nez ki, ha lathatova tesszuk:

UPDATE: Ez csak szimulatorban igaz, mert ott nem latszik a volume control. Az igazi device-on mashol van. Amugy sem az igazi megoldas ez, mert az overlay gombok akkor is ott lesznek, ha amugy a Default control-ok nem latszanak. Arra sajnos nincs lehetoseg, hogy megtudjuk eppen latszanak-e lejatszas kozben a default control-ok. Valoszinuleg az lesz a legjobb, ha az MPMovieControlModeHidden-re allitam es megcsinalom a sajat "Done", "Next", "Previous" controljaimat es esetleg meg egy mindig lathato controlt ami elrejti/megmutatja a tobbit. Ezzel csak az a baj, hogy igy sajat timeline control kene, amit meg nem tudom hogyan lehetne megcsinalni.

MPMediaPlayerController problemak

Tovabbra is tobb video egymas utan lejatszasat akarom megoldani es kozben belefutottam 2 problemaba:

1. Ha letrehozok egy MPMoviePlayerController-t akkor annak a retainCount-ja 1 ahogy kell, de amint meghivom rajta a play method-ot a retainCount 3 lesz. (A controller maga modul szinten van deklaralva, de ugyanez tortenik, ha helyben deklaralom, hozom letre es probalom lejatszani.) Igy persze egy sima release sem eleg a MPMoviePlayerDidFinishNotification kezeleseben. (Ugyanakkor, ha a controller-t nil-re allitom majd ujra letrehozom es meghivom a play mehtod-ot akkor mar csak 2 lesz a retainCount es nem 3.) Megneztem az Apple MoviePlayer peldakodjat es ott megjobban elszall a retainCount.

2. A masik problema, hogy ha az MPMoviePayerdidFinishNotification kezeleseben lenullazom a controller-t (akkor is, ha nil-re allitom) es utana egy masik videoval ujra letrehozom, majd meghivom rajta a play method-ot es a notification azert jott, mert a user megnyomta a "next" gombot, akkor a notification ujra megjon amint elindult a masodik video azaz a masodiknak rogton vege lesz. Ha a notification eredetileg azert jott, mert vege volt a videonak, akkor nincs ilyen problema.

Monday, January 4, 2010

UITableViewCell mozgatasa

Ha atvaltunk edit mode-ba, akkor meg nem tudjuk mozgatni a cellakat, ha nem implementaltuk (akar uresen) a tableView:moveRowAtIndexPath:toIndexPath methodot.

Ha nem akarjuk, hogy az osszes cella mozgathato legyen, akkor meg kell irni a tableView:canMoveRowAtIndexPath method-ot is.

Ha pedig nem szeretnenk, hogy akarhova at lehessen mozgatni akkor a tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath method-ot.

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