Questions for iPhone Developers

Recently, I began to learn about programming for the iPhone and after numerous online tutorials and books (most of which tell you to write here , without offering any explanation why and how things work) I have many unanswered questions, and it would be great if would someone help me clarify them.

Here:

1) In Interface Builder, what is the owner of the file, the first responder and delegate, and where is the actual code that draws the view?

2) When using Interface Builder and adding components to the screen, I understand that Interface Builder does not automatically write code for you, but how should I handle events triggered by various components? In terms of best design practice, should each component handle events in a separate file? (can such a file be a delegate of a component?), or is it better to just make the viewcontroller class implemented by all interfaces of its components?

3) When creating a UITableView, for example, and I define a function:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
}

I say that a tableView object of type UITableView has this callback function. Correctly? Therefore, if I have another UITableView called MyTableView, I have to write a function as such:

- (NSInteger)MyTableView:(UITableView *)MyTableView numberOfRowsInSection:(NSInteger)section {
    return [listOfItems count];
}
+3
source share
4 answers

.

1)
A. ? ? , nib? , - , initFromNib: on.

AClassName *theOwner = [[AClassName alloc] initFromNib:@"nibfile"];

nib - , , . , . , , . , . ( nib) , . nib, , , .

. ? , , , , , . - , . NSView, , , (, NSView NSResponder - ).

nib, . Cocoa Mac, , . iPhone , , ( ) . nib.

. ? , ? - . . . , . ", , TMI", - , , TMI. .

Interface Builder . UIApplication , , UIApplicationDelegate. , applicationDidFinishLaunching:, UIApplication .

. ? Apple Framework , NSView, NSWindow, NSTableView , . , , Apple, - , main.m.

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

UIApplicationMain (argc, argc, nil, nil) , . nib, UIApplication nib. . UIApplication ( nib) , MainWindow iPhone UIApplicationDelegate , .

, 1). , , , . , : , MainWindow.nib, nib, .

+5

1.) - () UIViewController, , IB (, GUI, Interface Builder)

, ( , )

- , , (, , ) (. )

2.) , ViewController ( ). , (, ). ( ..) IB ( - IBOutlet, , , IBAction). , , , , ViewController ( )

3.) , ( MyTableView ) , , . , [myTableView numberOfRowsInSection: 2]; , "myTableView", tableView... , UITableViewDelegate (, , , UITableViewController , .

, , - " iPhone" Mark LaMarche, .

Apple, , Builder .

: , iOS ( )

+2

:

  • Builder:
    • " " - Objective-C, . , .
    • " " ; , , , .
    • "" - , . Interface Builder " ", , iOS .
  • GUI, IBAction , . , , . , .
  • . , myTableView, , . :
    • (NSInteger) ,
    • tableView: . tableView:numberOfRowsInSection: , , MyTableView * .
    • (UITableView *) , UITableView
    • tableView , tableView

, View Viewer - , , , ..

+2

. , " xib" " " "". , , , "" , , , " , , , :

UIView UITableView

0

Source: https://habr.com/ru/post/1791547/


All Articles