将 NSMutableArrays 填充到自定义部分
想要将两个 NSMutableArray
填充到 tableView
的 2 个自定义部分;
我有两个带有事件的 NSMutableArray,我想将它们分成现在和今天部分。
对于第一部分:
我想从 nowEvents 数组中删除事件并将它们放入我的第一部分。
EventClass *event = [appDelegate.nowEvents objectAtIndex:indexPath.row];
event.startTime
是我的活动的开始时间
event.endTime
是我的活动的结束时间
对于第二部分: 删除现在正在发生的事件
EventClass *event = [appDelegate.todayEvents objectAtIndex:indexPath.row];
我想知道的是 numberOfRowsInSection
方法,它的外观和 cellForRowAtIndexPath
(这里我尝试了 NSInteger 部分= [indexPath section]; if (section == 0) { } if (section == 1) {}
- 但是如果我现在没有发生事件怎么办?)
Want to populate two NSMutableArray
s to 2 Custom Sections of tableView
;
I have two NSMutableArray
s with events and I want to split them to now and today sections.
For the first section:
I want to remove events from nowEvents Array and place them into my frist section.
EventClass *event = [appDelegate.nowEvents objectAtIndex:indexPath.row];
event.startTime
is the start time of my event
event.endTime
is the end time of my event
For 2nd section:
Remove the events that are happening now
EventClass *event = [appDelegate.todayEvents objectAtIndex:indexPath.row];
What I'd like to know is numberOfRowsInSection
method, how it would look like and cellForRowAtIndexPath
(here I've tried NSInteger section = [indexPath section]; if (section == 0) { } if (section == 1) {}
- but what about if I won't have an event that is happening now ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这样的事情应该可以工作
如果您现在没有发生事件,那么您的 nowEvent 数组将为空,因此在 numberOfRowsInSection 中将返回 0,因此不会调用 cellForRowAtIndexPath,因为没有任何内容可显示。希望这有帮助。
Something like this should work
If you don't have an event happening now then your nowEvent array will be empty so in the numberOfRowsInSection will return 0 and therefore the cellForRowAtIndexPath won't be called as there is nothing to display. Hope this helps.
根据情况,您的表视图中可以有 1 或 2 个部分,然后在 numberOfRowsInSection 中检查现在是否有任何事件(如果没有,则删除该部分)。所以你的如果会是这样的
You can have 1 or 2 sections in your table view depending on the case, then in your numberOfRowsInSection you check if there are any events now (if they aren't then you drop that section). So Your ifs would be something like