1. describes the order in which applications are started.
1) Program Entry Main function Creation uiapplication Instances and uiapplication The proxy instance.
2) in the uiapplication Proxy instance, override the startup method and set the root viewcontroller.
3) Add controls to the root viewcontroller to implement the application interface.
2. why many built-in classes such as Uitableviewcontrol 's delegate attribute are assign and not retain? Please illustrate.
Avoid circular references
here Delegate We're just trying to get it realized. Delegate method Object, and then get the pointer to this object, we don't expect to change it or do anything else, so we just use Assign get the pointer on it.
and with retain , the counter adds 1 . It is possible to expect to release the delegate object somewhere else , and then pass some judgment, such as whether it has been released or not, to do some work. But in fact it 's still 1retaincount, not released,
they hold each other . . RC never becomes 0;d ealloc will not execute , Neither will be released .
(an object does not need to manage itself Delegate life cycle, or no need to have the object, so we just have to know its pointer, and use the pointer to find the object to invoke the method)
3. How many methods must be implemented when using UITableView?
-(nsinteger) TableView: ( UITableView *) TableView numberofrowsinsection: (nsinteger) section;
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath;
4. Write a convenience builder.
-(ID) initwithname (nsstring *) name Age (int.) Age Sex (NSString *) sex{self = [super init]; if (self) {_name = name; _age = age; _sex = sex; } return self;} + (ID) initwithname (nsstring *) name Age (int.) Age Sex (NSString *) sex{person *p = ["Person Alloc]initwithname:name age:age Sex:sex]; return [P autorelease];}
5. UIImage There are several ways to initialize a picture? Describe the pros and cons of each
imagenamed: The system checks if the name is in the system cache first. Image , if any, returns directly, and if not, loads the image to the cache before returning.
Initwithcontentsoffile: System Cache is not checked and is loaded and returned directly from the file system.
imageWithCGImage:scale:orientation when scale= 1 when the image is the original size, Orientation develop the direction of the drawing image.
Imagewithdata;
6. answer the retaincount value of person and explain why
Person * per = [[Person alloc] init];
Self . person = per;
rc= 2 ;
Per.retaincount = 1 ,
Set Method Invocation retain
Setter method Reference count again + 1
7. What's wrong with this code :
@implementation Person
-(void) setage: ( int ) NewAge {
self. Age = NewAge;
}
@end
Self . Age on the left is also equivalent to Setter Method , which leads to a cycle of death.
8. What's wrong with this code and How to modify it
for (int i = 0; i < Somelargenumber; i++) {
nsstring *string = @ "ABC";
string = [string lowercasestring];
string = [string stringbyappendingstring:@ "xyz"];
NSLog(@ "%@", String);
}
Change: Add the auto-release pool to the loop @autoreleasepool{};
for (int i = 0; i < Somelargenumber; i++) {
@autoreleasePool {NSString *string = @ "ABC";
string = [string lowercasestring];
string = [string stringbyappendingstring:@ "xyz"];
NSLog (@ "%@", string);
}
}
Memory Leaks . method Self-releasing pool is too late to release .
in the for in the Loop , Add a memory pool yourself , produces a release of a
9. Intercept the string "20 | Http://www.baidu.com " ," | " characters before and after the data, output them separately.
NSString *str = @ "20|http://www.baidu.com" ;
nsarray *arr=[str componentsseparatedbystring:@ "|" ];
NSLog (@ "%@%@", [arr objectatindex:0], [arr objectatindex:1 ]);
Ten . Write a bubble sort with obj-c
nsmutablearray *array = [nsmutablearray arraywithobjects:@ ", @" @ "@" @ "@" 8 "@" ten ", nil];for (int i = 0; i < array.count - 1; i++) { int a = [array[i] intValue]; for (int j = i + 1; j < array.count; j++) { int b = [ array[j] intvalue]; if (a < b) { [array exchangeobjectatindex:i withobjectatindex:j]; } }}for (int i = 0; i < array.count; i++) { NSLog (@ "%@", Array[i]);}
This article is from the "http://fanyuecheng.blog.51cto.com/9529438/1686164 blog" blog, please make sure to keep this source.
iOS face three questions