开发者

iPhone: Problem with incrementing NSNumber & displaying transparent images (UIImageView)

开发者 https://www.devze.com 2023-01-14 17:51 出处:网络
I have a problem with NSNumber: I don\'t understand how to increment and decrement it! I\'ve tried int with [NSNumber intValue] and so on, but it didn\'t work!!!! I just want a page counter which can

I have a problem with NSNumber: I don't understand how to increment and decrement it! I've tried int with [NSNumber intValue] and so on, but it didn't work!!!! I just want a page counter which can be converted to an NSNumber at the end.

My second problem is displaying a (partially) transparent image in an UIImageView. It has ever a (white) background.

Thanks for answering,

Le Mi开发者_如何学编程lonkh


HI there

don't use nsnumbers, use ints. Much easier... (NSNumber is merely a wrapper for storing numbers, whereas int provides the default set of C based mathematical interfaces you are looking for, with relative ease - I'm sure you can do math with NSNumber -> although many people say NSDecimal is better. I say use floats, ints and doubles).

int pagenumber;
for(pagenumber = 0; pagenumber < 5; pagenumber++){
    NSLog(@"%i", pagenumber);
}

then if you really need it in an NSNumber then do:

NSNumber *pagenumberns = [NSNumber numberWithInt:pagenumber];

In answer to your second question I have never had that problem, but try doing: [ImageView setOpaque:no] and [ImageView setBackgroundColor:[UIColor clearColor]];

Hope some of that helps.


Thank you for your answer, but I need to declare them globally in my ...ViewController.h & .m files because all my methods use them.

Is is possible to do it like that, or have I to @property and @synthesize the int?

FooViewController.h:

@interface FooViewController : UIViewController {
 int *currentPage;
}

-(void)next;
-(void)changePage:(int)page;

FooViewController.m:

@implementation Post_GeheimnisViewController
@synthesize currentPage;

-(void)changePage:(int)page {
    //do some stuff here
}

-(void)next {
    currentPage++;
    [self changePage:currentPage];
} 

@end

Thank you for answering!
Le Milonkh

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号