簡體   English   中英

在Xcode中的分組表視圖中添加節

[英]Adding sections in a grouped table view in Xcode

我的代碼與其他代碼有些不同,但是可以工作。

我是應用程序編碼的新手,但我想將其中一些添加到部分中:

在此處輸入圖片說明

因此,其中一些人有自己的小組,每個小組都有一個小標題。

但是我的代碼看起來像這樣:

在此處輸入圖片說明

而且我不知道要插入什么才能正確執行。

(該圖片的下半部分是詳細視圖中的圖片,當您從表格視圖中選擇某些內容時,該視圖會顯示在詳細視圖中。)

(我知道Xcode在我的代碼中顯示錯誤,但仍然可以使用。)

誰能幫我?

您必須實現一些UITableView方法和委托方法(當然還要將您的類設置為該類的委托):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    //Here you must return the number of sectiosn you want
 }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //Here, for each section, you must return the number of rows it will contain
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
     //For each section, you must return here it's label
     if(section == 0) return @"header 1"; 
     .....
}

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    // Set up the cell...
    cell.text = // some to display in the cell represented by indexPath.section and indexPath.row;

    return cell;
}

這樣,您就可以根據需要排列數據:每個部分一個數組,一個帶有子數組的大數組,...。 只要您可以從上述方法返回所需的值,就可以使用Antthing。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM