IPhone development issue set

Source: Internet
Author: User

1. Set tags for ease of use

When multiple controls are placed in the cell, the tag can be easily distinguished. Using tags in other places is also convenient for programming. Haha

2. Today, I tried to delete a question, that is, simply add a button to the cell and click the button to delete it. This should not be allowed by Apple and is not set to the editing mode.
Type, I am using the direct reload data source method, but found a problem, that is, when selecting the row, I want to save the row number, but I cannot save it, I don't know why, do I?
Due to the delegate, it was the first time when the line was clicked again that the value had changed, but it was blank and depressing. Finally, I implemented it using nsmutablearray.
When selecting this row, I asked the nsmutablearray object addobject to set this row and then took the first value, that is, nsmutablearray.
Objectatindex: 0. The principle is still being explored.

3. reuse mechanism of uitableviewcell

Uitableviewcell only updates Content During loading. That is to say, if you add a button to the cell when loading the cell, suppose there are 100
Cell: when you set the tag, you add row more. The tag you want is from 0 to 99, but the result is not the same. What if you can display 10 cells in tableview?
The tag should only have 10. When you pull down the tag, only the displayed content is changed. The specific reuse mechanism also requires further research.

4. During nsarray initialization, I was dizzy today. I started to initialize the first program in nsarray.

Nsarray * array = [[nsarray alloc] initwithobjects :( @ "A", @ "B", nil)]; no compilation error, no running result, huh, huh. Remove the brackets. No problem. Affected by C.

5. Add tableview to uinavigation.

Table = [[uitableview alloc] initwithframe: cgrectmake (0, 0,320,440)];

[Table setdelegate: Self];

[Table setdatasource: Self];

[Self. View addsubview: Table];

6. Obtain the title of the button.

Uibutton * But = [[uibutton alloc] init];

[But settitle: @ "title" forstate: uicontrolstatenormal];

[But addtarget: Self action: @ selector (Click :) forcontrolevents: uicontroleventtouchupinside];

-(Void) Click :( ID) sender

{

Nsstring
* S = [Sender titleforstate: uicontrolstatenormal];

}

7. String truncation. Split by "|" and remove the following numbers as long as the previous part

Nsstring
* S =
@ "Haagen-Dazs, 4223 | king crab, 3717 | salmon, 3255 | tiramisu, 2733 | oyster, 1860 | grilled eel, 1451 | sashboard, 1430 | lobster color
Pull, 1252 | Arctic Bay, 1230 | Abalone slices, 772 | mango smoothie, 730 | grilled eel, 706 | salad, 692 | seafood dinner, 600 | ice cream, 508 | mango
Juice, 499 | Abalone slices, 357 | foundary wall, 308 | abalone, 295 | hgds, 262 ";

Nsmutablearray * array = [[s componentsseparatedbystring: @ "|"] retain];

Nsmutablearray * mutablearray = [[nsmutablearray alloc] init];

Int I = 0;

For (I; I <[array count]; I ++)

{

Nsstring
* S1 = [array objectatindex: I];

Nsarray * A = [S1 componentsseparatedbystring: @ ","];

[Mutablearray addobject: [A objectatindex: 0];

}

For (I = 0; I <[mutablearray count]; I ++)

{

Nslog ([nsstring
Stringwithformat: @ "% @", [mutablearray objectatindex: I]);

}

8. How to modify the name of Copyright 2009 _ mycompanyname _. All Rights Reserved. In xcode.

I used to see Lv posted this post on CC. At that time, the modification was successful, but I reinstalled the system and hung up again. The display was _ mycompanyname __, which was found again today, remember.

Defaults write com. Apple. xcode pbxcustomtemplatemacrodefinitions '{organizationname = "name ";}'

9. Convert audio to CAF format

On Mac, you can use the afconvert command to Convert audio files to CAF files.

Afconvert-F Caff-D lei16 @ 44100-C 1 in.wav out. CAF

-F specifies the file format

-D data format, @ 44100 refers to the sampling rate

-C channel count

10. How to obtain uiimage from core graphics

-(Void) viewdidload

{

[Super viewdidload];

Uigraphicsbeginimagecontext (cgsizemake (20, 20 ));

Cgcontextref CTX = uigraphicsgetcurrentcontext ();

Cgcontextbeginpath (CTX );

Cgcontextaddarc (CTX, 10, 10, 10, 0, 2 * m_pi, 1 );

Cgcontextsetrgbfillcolor (CTX, 1, 0, 0, 1 );

Cgcontextfillpath (CTX );

Uiimage * redball = uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

Uiimageview * redballview = [[uiimageview alloc] initwithimage: redball];

Redballview. Center = cgpointmake (160,330 );

[Self. View addsubview: redballview];

}

11. Differences between uiimage imagenamed and uiimage imagewithcontentsoffile

Uiimage imagenamed will provide cache for this image, so if you need the same image again, the image will be cached internally

It is not loaded from the resource. The bad message is that the iPhone will cache the image. In this way, memory leakage occurs if there are too many images.

Uiimage imagewithcontentsoffile does not provide cache.

12. A white screen is displayed when you use IB to add navigation.

At the beginning, I deleted the window, and it turned out to be a white screen with nothing and nothing. I forgot to associate the window in APP delegate with the window. If you use IB to create viewcontroller. XIB, you can delete it completely. The running result is not affected.

13.-(cgfloat) tableview :( uitableview *) tableview
Heightforrowatindexpath :( nsindexpath *) indexpath can be used to change the height of a cell.
Row can change the height of each row at will, for example

-(Cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath

{

If ([indexpath row] = 2)

Return 80;

Else {

Return 100;

}

}

14. Set the iPhone startup Screen

Add the image named default.png to the resourcefolder of xcode. You can use the organizer tool to capture the iPhone.

Organizer is a tool included in xcode. It is started by selecting xcode> WINDOW> organizer. In this way, the screen will be run on the black screen a moment before the program is loaded!

15. Play the caf audio file

Introduce audiotoolbox. framework. Import the audio file and declare the variable systemsoundid sound1;

Nsstring
* Path1 = [[nsbundle mainbundle] pathforresource: @ "sound1" oftype: @ "caf"]; obtain the audio file path

Cfurlref sound1url = (cfurlref) [nsurl fileurlwithpath: path1]; convert the path to cfurlref

Audioservicescreatesystemsoundid (sound1url, & sound1); load the audio file and associate it with the specified soundid

Add audioservicesplayalertsound (sound1) to the desired playback address.

16. Set view to rounded corner

As we can see from CC today, the experiment has been done, and the effect is quite good. Haha

First import quartzcore. Framework, # import <quartzcore/quartzcore. h>

Then add the following two lines of code:

View. layer. cornerradius = 8; // rounded corner

View. layer. maskstobounds = yes; // draw a rounded corner at the Layer

17. Set coordinates and sizes

Cgpoint A = cgpointmake (10, 20 );

Cgsize B = cgsizemake (40, 40 );

Cgrect AA = cgrectmake (10, 30,240,240 );

18. Convert uicolor to cgcolor

Uicolor * redcolor = [uicolor redcolor];

Cgcolor * redcolor = redcolor. cgcolor;

19. calayer is a layer. You can control its size, rotation, angle, coordinate change, content, and other information at will. These changes can also be expressed through animation. Uiview all the content you can see is followed by a layer. Add a calayer as defined below.

Calayer * layer = [[calayer alloc] init]; // defines a Layer

Cgrect AA = cgrectmake (10, 30,240,240); // you can specify the coordinates and sizes of the layer.

Layer. Frame = AA;

Uicolor * c = [uicolor redcolor];

[Layer setbackgroundcolor :( C. cgcolor)]; // sets the background of the layer. Because layer setbackgroundcolor uses cgcolor, a conversion is required.

[Self. View. layer insertsublayer: layer atindex: 0]; // Add this layer to self view.

20. When using xcode to write a program, you can jump to the relevant instructions in document by option + double-clicking on the class method, which is very convenient!

21. decompress the tgz file using the command line:

Tar xzvf filename

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.