gpt4 book ai didi

ios - TableView 从 : numberOfRowsInSection 中的最后一部分开始

转载 作者:行者123 更新时间:2023-11-30 13:05:16 25 4
gpt4 key购买 nike

这可能看起来与此重复:numberOfRowsInSection starts with last section ,但是提供的解决方案对我来说不起作用,很久以前就有人问过它,而且它是用 Objective-C 编写的。 AFAIK 语言与此无关。

步骤:

  1. 调用API
  2. 向数组添加响应 - 10 个结果
  3. 重新加载表格
  4. numberOfRowsInSections 被调用。
  5. print("section:\(section)") in numberOfRowsInSections 打印

    section: 9
    section: 0
    section: 1
    section: 2
    section: 3
    section: 4
    section: 5
    section: 6
    section: 7
    section: 8

这是不受欢迎的行为,因为我希望每个部分中有不同的行数。

由于 numberOfRowsInSections 决定每个部分中的单元格数量,因此我根据每个数组中的某些值来计算部分的数量。

回应:

{
count = 10;
"post_results" = (
{
attachment = "";
category = "An Act of Kindness";
"comments_count" = 5;
description = xjjxjsj;
"last_comment" = {
"comment_date" = "2016-09-13 08:24:38";
"comment_id" = 199;
description = "dddg\n";
"user_picture" = "/uploads/2016/09/popup-40x40.png";
username = testing1;
};
"likes_count" = 0;
"post_date" = "2016-09-13 07:59:17";
"post_id" = 1866;
"share_count" = "";
title = jdjsjsj;
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = testing1;
},
{
attachment = "";
category = "In The News";
"comments_count" = 6;
description = "check timing";
"last_comment" = {
"comment_date" = "2016-09-13 10:05:11";
"comment_id" = 207;
description = "hdhd\n";
"user_picture" = "/uploads/2016/09/popup-40x40.png";
username = testing1;
};
"likes_count" = 0;
"post_date" = "2016-09-13 07:06:46";
"post_id" = 1864;
"share_count" = "";
title = "new post";
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = testing1;
},
{
attachment = "";
category = "An Act of Kindness";
"comments_count" = 2;
description = "timer testing";
"last_comment" = {
"comment_date" = "2016-09-13 10:01:41";
"comment_id" = 201;
description = "hddn\n";
"user_picture" = "/uploads/2016/09/popup-40x40.png";
username = testing1;
};
"likes_count" = 0;
"post_date" = "2016-09-13 06:56:36";
"post_id" = 1862;
"share_count" = "";
title = hiii;
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = testing1;
},
{
attachment = "";
category = "An Act of Kindness";
"comments_count" = 0;
description = Hloo;
"last_comment" = {
"comment_date" = "";
"comment_id" = "";
description = "";
"user_picture" = "";
username = "";
};
"likes_count" = 0;
"post_date" = "2016-09-13 06:54:48";
"post_id" = 1860;
"share_count" = "";
title = testing;
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = testing1;
},
{
attachment = "";
category = "Making a Difference";
"comments_count" = 0;
description = TestContentdfdf899;
"last_comment" = {
"comment_date" = "";
"comment_id" = "";
description = "";
"user_picture" = "";
username = "";
};
"likes_count" = 0;
"post_date" = "2016-09-13 06:54:14";
"post_id" = 1858;
"share_count" = "";
title = TestTitleerer899;
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = max57;
},
{
attachment = "/uploads/2016/09/Koala6-440x330.jpg";
category = "Making a Difference";
"comments_count" = 0;
description = TestContentdfdf89;
"last_comment" = {
"comment_date" = "";
"comment_id" = "";
description = "";
"user_picture" = "";
username = "";
};
"likes_count" = 0;
"post_date" = "2016-09-13 06:49:07";
"post_id" = 1855;
"share_count" = "";
title = TestTitleerer89;
"upload_type" = 1;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = max57;
},
{
attachment = "www.praizbuk.com";
category = "An Act of Kindness";
"comments_count" = 0;
description = "";
"last_comment" = {
"comment_date" = "2016-09-13 08:16:01";
"comment_id" = 194;
description = "jddj\n";
"user_picture" = "/uploads/2016/09/popup-40x40.png";
username = testing1;
};
"likes_count" = 1;
"post_date" = "2016-09-09 07:12:44";
"post_id" = 1846;
"share_count" = "";
title = db;
"upload_type" = 3;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = kkk;
},
{
attachment = "/uploads/2016/09/dummy3.mp4";
category = "An Act of Kindness";
"comments_count" = 1;
description = xbbdbd;
"last_comment" = {
"comment_date" = "2016-09-09 07:17:36";
"comment_id" = 192;
description = "uugh\n";
"user_picture" = "/2016/09/popup-40x40.png";
username = kkk;
};
"likes_count" = 1;
"post_date" = "2016-09-09 06:19:20";
"post_id" = 1842;
"share_count" = "";
title = zyhh;
"upload_type" = 2;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = kkk;
},
{
attachment = "/uploads/2016/09/dummy2.mp4";
category = "In The News";
"comments_count" = 0;
description = "new video uploaded";
"last_comment" = {
"comment_date" = "";
"comment_id" = "";
description = "";
"user_picture" = "";
username = "";
};
"likes_count" = 0;
"post_date" = "2016-09-09 05:49:48";
"post_id" = 1838;
"share_count" = "";
title = "my video";
"upload_type" = 2;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = kkk;
},
{
attachment = "";
category = "An Act of Kindness";
"comments_count" = 0;
description = Vdfdfdfdfd;
"last_comment" = {
"comment_date" = "";
"comment_id" = "";
description = "";
"user_picture" = "";
username = "";
};
"likes_count" = 0;
"post_date" = "2016-09-08 12:00:24";
"post_id" = 1836;
"share_count" = "";
title = fff;
"upload_type" = 0;
"user_image" = "/uploads/2016/09/popup-40x40.png";
"user_name" = kkk;
}
);
status = ok;
}

TableView 方法是:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let post = arrPost[section]
let comment = post.last_comment

print("section: \(section)")

if post.upload_type! == "0" {
if let _ = comment!.comment_id {
return 2
} else {
return 1
}
} else {
if let _ = comment!.comment_id {
return 3
} else {
return 2
}
}

}

最佳答案

响应参数类型存在一些问题。

最终结论如 @Avt 在评论中所说:

If correctly implemented UITableViewDataSource/delegate it should work regardless which section is requested first.

关于ios - TableView 从 : numberOfRowsInSection 中的最后一部分开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39467461/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com