Thursday, April 25, 2013

Opcionalis delegate method

Egyreszt a @protocol-ban a method kapja meg az @optional direktivat:

@protocol MyProtocol
    @optional
    -(void)optionalProtocolMethod:(id)anObject;
@end

masreszt mivel ez onmagaban csak arra jo, hogy compiler ne adjon warningot meg a method meghivasa elott azt is meg kell nezni, hogy a delegate implementalja-e ezt a method-ot:

if ([delegate respondsToSelector:@selector(myOptionalMethod)]) {
    [delegate myOptionalMethod];
}
A protocol az NSObject-bol kell szarmazzon, mert annak a resze a respondsToSelector

Thursday, April 18, 2013

UIColor

Eleg furan mukodik, ha egy control RGB szinet be akarjuk allitani. a colorWithHue:saturation:brightness:alpha:-nal nem a sima RGB ertekeket kell megadni, hanem egy 0.0 es 1.0 koze eso float-ot, amit ugy kapunk meg, ha az alltalunk ismert RGB ertekeket elosztjuk 255-tel. Tehat peldaul a Red amit kaputunk 50, akkor itt 0.196-ot (50/255) kell megadnunk.

Ha egy UIColor-bol pedig ki szeretnenk nyerni az ertkeket arra a getRed:green:blue:alpha: methodot hasznalhatjuk valahogy igy:

UIColor *color = //get the color to log
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
NSLog(@"mycolor red:%f green:%f blue:%f alpha:%f", red, green, blue, alpha);

Persze ha nem RGB hanem HSB akkor arra ott van a colorWithHue:saturation:brightness:alpha: es a 
getHue:saturation:brightness:alpha:

Monday, April 8, 2013

Email kuldese app-bol

MFMailComposeViewController-el egyszeruen:


- (void) sendEmail {
    if (![MFMailComposeViewController canSendMail]) {
        HBAlert(@"Can't send email", @"Sorry, your device is not able to send email");
        return;
    }
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    [mailer setMailComposeDelegate:self];
    NSString *subject = @"Whatever subject;
    [mailer setSubject:subject];
    NSString *body = @"This is a test email from my app.";
    [mailer setMessageBody:body isHTML:NO];
    [mailer setModalPresentationStyle:UIModalPresentationFormSheet];
    [self presentViewController:mailer animated:YES completion:nil];
}


- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    switch (result) {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved as draft");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail is sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Sending mail failed");
            break;
        default:
            break;
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

Friday, April 5, 2013

DigitalColor Meter

Ha mac os-en kell egy keppont szinet megallapitani, akkor DigitalColor Meter.

Thursday, April 4, 2013

Handling Popover Controllers During Orientation Changes

Van egy azonos cimu bejegyzes az Apple-nel ami szerint:

When showing a popover controller, there are times when you will need to handle how the popover controller appears after a change in device orientation.

Situations when handling is required:

If the popover controller is presented from a target rectangle using the –presentPopoverFromRect:inView:permittedArrowDirections:animated: method of UIPopoverController.
If the popover controller is presented from a bar button item that is removed after the rotation has finished.

es ilyenkor a megoldas, ha ujra meghivjuk a presentPopoverFromRect:inView:permittedArrowDirections:animated: method-ot a didRotateFromInterfaceOrientation: eventben, csak azt nem teszik hozza, hogy elotte azert erdemes megnezni, hogy egyaltalan latszott-e a Popover Controller. Szoval helyesen igy nez ki:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
if ([myickerPopover isPopoverVisible]) {
[[self myPickerPopover] presentPopoverFromRect:
[[self myButton] frame] 
inView:[self view] 
permittedArrowDirections: UIPopoverArrowDirectionAny animated:YES];
}
}

Felteve, hogy a myPickerPopover es a myButton elerheto property.

dequeueReusableCellWithIdentifier:forIndexPath:

iOS 6-ban jelent meg a regi dequeueReusableCellWithIdentifier: mellett es ahogy a doksiban is kiemelik
Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

Azaz vagy marad a regi modszer ami akar 2-es iOS-en is mukodik:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
return cell;
}


Vagy ha minimum 6-oson hasznaljuk akkor:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    return cell;
}

de ilyenkor fontos, hogy a viewDidLoad-ba betegyuk ezt:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];