2010-08-21 76 views
0

傢伙,我在iPhone新手而不是編程,我的疑惑是,的UITableView在iPhone

  1. 是否有可能增加不止一個的UITableView多在同一個屏幕? ,如果是這樣,請給我提供示例代碼/資源,我可以找到..

  2. 第二個UITableView必須相應地根據第一個UITableView中的選擇進行更改。

由於提前

回答

0

Here's一個示例代碼。但更好的方法是,爲這兩個表提供不同的委託/數據源。

要改變取決於table1的選擇表2的內容,你可能只需要使用[表2 reloadData]在

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
1

這是可能的,但您所描述的感覺可能是一個UI慣例衝突。您應該每個屏幕呈現一個UITableView,其中第一個「鑽取」一行,然後第二個UITableView - 就像一個層次結構。

0

你可以考慮在uiTableview中使用Section。

這將有助於在2 UiTableView中加載內存腳印。

首先設置加載部分的數量,並且應該滿足一定的條件。 設置爲2段,叫[tableview reloadData]

你設置部分的數量爲2

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;你會使用設置在每個部分行數這應該加載- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;

if (section == 0){ do something} else { do something else} 

這假設你有2個部分。

最後內- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;,你應該使用相同的,如果其他人來檢查哪些部分和加載相應的數據。

2
-(void)loadView 
{ 
    // create and configure the view 
    CGRect cgRct = CGRectMake(0, 10, 320, 100); //define size and position of view 
    myView = [[UIView alloc] initWithFrame:cgRct]; //initilize the view 
    myView.autoresizesSubviews = YES; //allow it to tweak size of elements in view 
    self.view = myView; //set view property of controller to the newly created view 
    UITableView * tableView = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStylePlain]; 
    tableView.editing = YES; 
    tableView.dataSource = self; 
    tableView.delegate = self; 

    cgRct = CGRectMake(0, 120, 320, 100); //define size and position of view 
    UITableView * tableView1 = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStylePlain]; 
    tableView1.editing = YES; 
    tableView1.dataSource = self; 
    tableView1.delegate = self; 

    cgRct = CGRectMake(0, 230, 320, 100); //define size and position of view 
    UITableView * tableView2 = [[UITableView alloc] initWithFrame:cgRct style:UITableViewStylePlain]; 
    tableView2.editing = YES; 
    tableView2.dataSource = self; 
    tableView2.delegate = self; 

    [self.view addSubview:tableView]; 
    [self.view addSubview:tableView1]; 
    [self.view addSubview:tableView2];   
}