在 Xcode 的分组表视图中添加部分

发布于 2024-12-14 11:43:07 字数 547 浏览 6 评论 0原文

我的代码与其他人有点不同,但它有效。

我是应用程序编码的新手,但我想添加一些 这些分为几个部分:

在此处输入图像描述

因此,其中一些人有自己的小组,每个小组都有一个小标题。

但我的代码如下所示:

在此处输入图像描述

,但我不知道要插入什么才能正确执行此操作。

(该图片的下半部分是详细视图中的图片,当您从表视图中选择某些内容时,它会显示在详细视图中。)

(我知道 Xcode 在我的代码中显示错误,但它仍然有效。)

任何人都可以帮我?

My code is a little different to others, but it works.

I am new to app coding, but I would like to add some of
these into sections:

enter image description here

So some of them have their own group with a small title to each.

But my code looks like this:

enter image description here

and I don't know what to insert to do it right.

(The bottom half of that picture is the pictures in the detail view, that shows up in the detail view when you select something from the table view.)

(I know Xcode shows errors in my code, but it still works. )

Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅的被狗咬 2024-12-21 11:43:07

您必须实现一些 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 就可以了。

You have to implement some UITableView methods and delegate methods (and of course set your class as the delegate of the class) :

- (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;
}

With that, you can arrange your data as you want : One array for each section, one big array with sub arrays, ... as you want. Antthing will be ok as far as you can return the wanted values from the methods above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文