2011-02-05 24 views
0

我搜索了四周,我似乎無法弄清楚如何做到這一點。這並沒有幫助,我真的不知道我完全做了什麼,但我希望這會有所幫助。將數據/行添加到UITableView(一個視圖上的多個表)

我正在創建一個iPad應用程序。簡而言之,它是一個複雜的秒錶,將在一個視圖上進行拆分(用於運行)。

我有一個主時鐘和5個按鈕分開分割。所有的工作。但是,我想記錄這些分割,我認爲在一個可以滾動的表格中執行它會很棒。

我在一個視圖上有5個UITableViews。我在網上找到了一些關於「數據源協議」的東西,並且只需要一張桌子就可以很好地工作。當我試圖爲每張桌子單獨工作時,事情就變成了廢話。此外,它似乎是一個簡單的任務代碼噸。

我有5個可變陣列已經存在。我真的不知道該怎麼做,任何幫助都會很棒!

另外,如果可能的話,我需要按下按鈕清除表格...看起來很簡單,但我真的不知道。

謝謝!

回答

2

您需要設置的UITableViewDelegate和UITableViewDataSource您的所有表格,將實現一類以下方法:

對於UITableViewDataSource:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

因爲這些方法通過調用tableview,你應該很容易返回正確的數據爲有問題的tableview(你已經是stori ng在NSMutableArray中)。你仍然需要爲陣列顯示不同的內容,但我相信你會設法做到這一點。 NSIndexPath基本上告訴你應該顯示數組的哪一部分。假設,現在,你是在一個未分組表的工作,你會簡單的創建一個新的細胞,並用你的陣列,它是由indexPath確定的內容填充:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MyNiceIdentifier"; 
    cell = [aTableView dequeueReusableCellWithIdentifier:NavigationCellIdentifier]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.tag = 500; 
    } 

    cell.textLabel = [myArray objectAtIndex:indexPath.row]; 
} 

中的其它數據源方法,你簡單的返回了該陣列計數:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if(tableView == myFirstTableView) { 
     return [myFirstArray count]; 
    } 
} 

的UITableViewDelegate的你可能會經常使用的方法是這樣的:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

您可以使用它的回報給定indexPath處單元的所需高度。

設置數據源和委託是簡單地做:

myTableView.delegate = ... 
myTableView.dataSource = ... 

看到這個文檔:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate

請同時參閱本文檔: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html

+0

謝謝你的答覆。但是我不知道如何爲每個表實現這個。我試過了,第二張桌子模仿了第一張桌子。 「*」是什麼意思?我很感激幫助。 – motoxrider365 2011-02-05 18:51:50

相關問題