The use of NSBundle!


First lock the link: http://blog.csdn.net/totogo2010/article/details/7672271

In this section, the author tell us how to use a Bundle ,But when I use the Bundle! I had a problem……

I delete the image or other resource (or changed) in the Xcode,then i run the code,the app would not change!!

eg: I copy a sqlite file from the Xcode to the app, when I change the file in the workspace , the app in the simulator 

is not change!!

Finaly: I fixed it by changed the ****.app this bundle in : ……/Users/appxy_dev_056/Library/Developer/Xcode/DerivedData/PeriodPal-brninsdxsnedjoejuhpqlgbklbev/Build/Products


iOS Create a Label and use bundle

first  lock the code:

 

 

{

 

    [super
viewDidLoad];

 

    NSBundle * mainBundle = [NSBundle
mainBundle];

 

    NSString * imagePath = [mainBundle
pathForResource
:@”QQ20130912-1″ ofType:@”png”];

 

    NSLog(@”%@”, imagePath);

 

 

    UIImage *image = [[UIImage
alloc] initWithContentsOfFile:imagePath];

 

    UIImageView *imageView = [[UIImageView
alloc] initWithImage:image];

 

    [imageView setFrame:CGRectMake(0,
20, 320, 100)];

 

    [self.view
addSubview
:imageView];

 

    [image release];

 

    [imageView release];

 

// Do any additional setup after loading the view.

 

 

 

    UIView *contentView = [[UIView
alloc] initWithFrame:[[UIScreen
mainScreen] applicationFrame]];

 

    contentView.backgroundColor = [UIColor
blackColor];

 

    self.view = contentView;

 

    [contentView release];

 

    CGRect labelFrame = CGRectMake(40.0f,
200.0f, 240.0f,
60.0f
);

 

    UILabel *frontLabel = [[UILabel
alloc] initWithFrame:labelFrame];

 

    frontLabel.text = @”Hello World!”;

 

    frontLabel.font = [UIFont
fontWithName:@”Georgia”
size
:24.0f];

 

    frontLabel.textColor = [UIColor
colorWithRed:0.82f
green
:1.0f blue:0.286f
alpha:1.0f];

 

    frontLabel.backgroundColor = [UIColor
colorWithRed:0.0f
green
:0.0f blue:0.0f
alpha:0.0f];

 

    [contentView addSubview:frontLabel];

 

    [frontLabel release];

 

 

 

}

 

 

 

use this ,you can know how a bundle work!!

 

The ThreeWays about Radio , the multiple choice ……

 

First come to the three gif image!

 

link form  baidu pan

 

 

first :main code 

{

    UIButton * tempBt = sender;    

    if (tempBt.backgroundColor == [UIColorblackColor]) {

        tempBt.backgroundColor = [UIColorredColor];

        return;

    }else{

        tempBt.backgroundColor = [UIColorblackColor];

        return;

    }

}

 

 

 

 

second:

{

    UIButton *tempBtn = sender;

    UIButton *temBt2 ;

    NSArray *array = [NSArrayarrayWithObjects:Bt1,Bt2,Bt3,nil];

    for (int i =0; i<array.count; i++) {

        temBt2 = [array objectAtIndex:i];

        temBt2.backgroundColor = [UIColorblackColor];

    }

    if (Flag1 ==0) {

        tempBtn.backgroundColor = [UIColorredColor];

        intAddTag++;

        tempBtn.tag = intAddTag;

        Flag1 = 1;

        return;

    }

 

    if (Flag1) {

        if (intAddTag == tempBtn.tag) {

            tempBtn.backgroundColor = [UIColorblackColor];

            Flag1 = 0;

        }else{

            tempBtn.backgroundColor = [UIColorredColor];

            intAddTag++;

            tempBtn.tag = intAddTag;

            Flag1 = 1;

        }

    }

}

 

Third main code:

{

    UIButton *tempBtn = sender;

    UIButton *temBt2 ;

    NSArray *array = [NSArrayarrayWithObjects:Bt1,Bt2,Bt3,nil];

    for (int i =0; i<array.count; i++) {

        temBt2 = [array objectAtIndex:i];

        temBt2.backgroundColor = [UIColorblackColor];

    }

    tempBtn.backgroundColor = [UIColorredColor];

}

The difference between the int value ++; and the value;


First come to the code:

{

    intAddTag = 3000;

    intAddTag++;

    Flag1 = intAddTag;

    NSLog(@”flag1 %d,intAddTag %d=========”,Flag1,intAddTag);

    intAddTag = 3000;

    Flag1 = intAddTag++;

    NSLog(@”flag1 %d,intAddTag %d=========”,Flag1,intAddTag);


}

like up, the test builder is IOS ,Xcode 5.0 

print :

2013-09-11 16:28:59.530 PeriodPal[5010:a0b] flag1 3001,intAddTag 3001=========

2013-09-11 16:28:59.530 PeriodPal[5010:a0b] flag1 3000,intAddTag 3001=========


so the value is different!!!!