[英]UIViewController, UIView and View hierarchy in ios4 SDK / iphone development
有人可以在iphone / ipad開發中推廣視圖層次結構嗎?
我想知道什么是在屏幕上顯示文本框所需的“根”元素。
我也想知道如何無需使用NIB即可填充UITableViewController子類。
最小組件是:
Window
UiViewController
UIView
UITextBox
要么
Window
UIView
UITextBox
@ Richard J. Ross III
我在哪里放myTableView?
Window
myTableView
myTableView是什么類型的?
最小的組件是,但建議使用UIViewController
,因為它允許你用UITableViews
, UITabBars
等做一些很酷的東西.UITableViewController子類沒有nib:
#import <UIKit/UIKit.h>
@interface MyController : UITableViewController
// custom methods here
@end
@implementation MyController
–(UITableViewCell *) tableView:(UITableView *) view cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
return [[[UITableViewCell alloc] init] autorelease];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// initializes the table with 10 rows
return 10;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"the user selected row: %@", indexPath);
}
@end
然后,要使用該自定義控制器:
MyController *control = [[MyController alloc] initWithStyle:UITableViewStylePlain];
// now hook it up!
myTableView.dataSource = control;
myTableView.delegate = control;
[control release];
對不起我的語法錯誤,我在沒有IDE的情況下編寫了此代碼(例如,直接在stackoverflow上)。
第一個猜測是正確的。 UIViewController管理一個視圖屬性,它是一個UIView。 當某些事件發生時,控制器負責處理事務。 如果用戶旋轉了他的設備,則viewController是聽到它的對象。 如果您已為此事件編碼,則viewController將向UIView傳遞指令以進行旋轉。 viewController中有一些特殊代碼可以決定在視圖出現,消失,加載,卸載等時要執行的操作。
UITableViewController管理tableView。 在默認的XCode設置中,Table View DataSource和Delegate是UITableViewController子類。 委托通過選擇行,滾動等來管理用戶與表交互時發生的情況。數據源包含填充表中行,頁眉和頁腳的信息。
如果要在tableViewCell中顯示文本框,則需要UITableView對象和UITextField。 您必須使dataSource為表提供一行UITextField,並將其添加到UITableViewCell的視圖中,該視圖稱為contentView。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.