- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
=> 我知道,这是个愚蠢的问题,但这对像我这样的新 iPhone 开发者来说更为重要。
这里我有与UITableView 部分 相关的问题:
第一个问题:我有一个问题,我如何从多个部分开始我的 UITableView 部分的编号 0?
例如:
我在 UITableView
和 numberOfSectionsInTableView
委托(delegate)方法中有 11 个部分,我的部分首先从第 11 个部分开始,然后是 0,1,2,3, 4、5、6、7、8、9 和 10。那么我怎样才能以 0 号开始我的节号,然后按原样。
第二个问题: 在 titleForHeaderInSection
委托(delegate)方法中,我的 tableView 的所有部分都重复了 3 次。在当前的 ViewController 中,我向上或向下滚动 UITableView,然后部分显示正常(0 到 11),UITableView 的这个正常部分在重复部分 3 次后显示。
例如:
我在 titleForHeaderInSection
委托(delegate)方法中使用 NSLog (@"%d ", section );
然后在控制台中显示如下
控制台输出:
2012-09-17 12:27:47.424 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.426 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.427 Quotes2You[1623:f803] 11
2012-09-17 12:27:47.428 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.429 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.430 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.431 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.432 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.433 Quotes2You[1623:f803] 2
2012-09-17 12:27:47.434 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.435 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.436 Quotes2You[1623:f803] 3
2012-09-17 12:27:47.436 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.437 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.438 Quotes2You[1623:f803] 4
2012-09-17 12:27:47.438 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.439 Quotes2You[1623:f803] 5
2012-09-17 12:27:47.440 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.441 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.462 Quotes2You[1623:f803] 6
2012-09-17 12:27:47.463 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.464 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.465 Quotes2You[1623:f803] 7
2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.466 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.467 Quotes2You[1623:f803] 8
2012-09-17 12:27:47.472 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.476 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.478 Quotes2You[1623:f803] 9
2012-09-17 12:27:47.480 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.481 Quotes2You[1623:f803] 10
2012-09-17 12:27:47.487 Quotes2You[1623:f803] 0
2012-09-17 12:27:47.487 Quotes2You[1623:f803] 1
2012-09-17 12:27:47.489 Quotes2You[1623:f803] 2
首先重复所有部分 3 次,然后当我滚动 UITableView 然后部分从 0 开始(正常)
我的代码在这里:
ThirdViewController.h
@interface ThirdViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
UITableView *tblCustomer;
NSArray *listOfsection;
}
@property (nonatomic,retain) UITableView *tblCustomer;
@property (nonatomic,retain) NSArray *listOfsection;
@end
ThirdViewController.m
@synthesize tblCustomer , listOfsection;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tblCustomer = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,417) style:UITableViewStyleGrouped];
self.tblCustomer.delegate = self;
self.tblCustomer.dataSource = self;
[self.view addSubview:self.tblCustomer];
self.listOfsection = [[NSArray alloc] initWithObjects:@"Name", @"Company", @"Address", @"Email", @"Mobile", @"Phone", @"Potential", @"Sales Status", @"Genre", @"Distributor", @"Dist Rep", @"Internal Notes", nil];
}
#pragma mark - UITableView Datasource Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
return [self.listOfsection count];
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
int numSection=0;
if (section == 2)
numSection = 5;
else
numSection = 1;
return numSection;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// here is my code cellForRowAtIndexPath as section wise
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSLog(@" %d ", section);
NSString *sectionHeader = nil;
sectionHeader = [self.listOfsection objectAtIndex:section];
// here is section overwrite //
return sectionHeader;
}
#pragma mark - Memory Management
-(void)dealloc
{
[super dealloc];
[self.listOfsection release];
[self.tblCustomer release];
}
提前致谢
最佳答案
你问:
First Problem : i have question that how can i start my UITableView section with number 0 from multiple section ?
我认为您的惊愕源于这样一个事实,即它们不是以严格顺序的方式调用的。这就是它恰好起作用的方式,您无法更改此行为。显然,您的部分在应用程序中以正确的顺序出现,但它们恰好不会按顺序调用。这就是事件驱动编程的本质。但是,我在你的代码中没有看到任何基于这个执行顺序的中断,但也许你的代码中有一些你没有包含在这里的东西需要严格顺序调用这些方法,如果是这样,你会必须重构该代码。但是我在上面的代码片段中没有看到类似的东西。 UITableViewDataSource
委托(delegate)方法的性质意味着您可以(并且应该)以不依赖于调用单元格或部分的顺序的方式编写您的方法。永远不要依赖 UI 中的事件序列来控制如何构建 View 的底层模型。
second problem : in titleForHeaderInSection delegate method my all sections of tableView is repeat 3 times. and at current ViewController i scrolling UITableView up or down then section display as normal (0 to 11 ) this normal section of UITableView display after repetition of section 3 times.
如果它被连续调用三次,我会感到惊讶。我敢打赌(特别是考虑到您的日志显示格式略有不同的 NSLog
语句的证据)您的代码中某处还有其他 NSLog
语句。我会尝试将您的 NSLog
语句更改为:
NSLog(@"%s section=%d", __FUNCTION__, section);
这样,(a) 您知道它是从哪个方法记录的; (b) 通过在格式化字符串中添加描述性的 "section="
,这意味着如果您永远不会对正在记录的数字感到困惑。我敢打赌,并非所有这三个 NSLog
语句都来自您的 titleForHeaderInSection
。就个人而言,我不再在没有 __FUNCTION__
引用的情况下将 NSLog
语句放入我的代码中,因为很容易混淆生成什么 NSLog
声明。
但即使 titleForHeaderInSection
被多次调用,又如何呢? iOS 已经在后台进行了优化,可以做各种事情。了解正在发生的事情对我们有好处(例如,确保您不会在 titleForHeaderInSection
中做一些计算密集型或网络密集型事件之类的傻事),但现在是拥抱 serenity prayer 的时候了。并欣赏我们作为开发人员可以控制的东西,以及我们不能控制的东西。 (UITableViewDataSource
调用的顺序和数量是我们无法控制的事情之一。)只要您不是对方法进行冗余调用的来源(例如,执行不必要的 reloadData
调用),我不会为此担心。
总而言之,虽然如果 titleForHeaderInSection
被连续调用三次我会感到惊讶,但不要依赖它只被调用一次。我认为表格 View 可能会为表格的每个部分调用一次(可能是为了计算整个表格的高度,以便适当调整滚动条的大小),然后再次为屏幕上可见的部分调用一次(实际显示节标题)。
关于iphone - 当我有多个部分时,如何以数字 0 开始我的 UITableView 部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12455094/
SQLite、Content provider 和 Shared Preference 之间的所有已知区别。 但我想知道什么时候需要根据情况使用 SQLite 或 Content Provider 或
警告:我正在使用一个我无法完全控制的后端,所以我正在努力解决 Backbone 中的一些注意事项,这些注意事项可能在其他地方更好地解决......不幸的是,我别无选择,只能在这里处理它们! 所以,我的
我一整天都在挣扎。我的预输入搜索表达式与远程 json 数据完美配合。但是当我尝试使用相同的 json 数据作为预取数据时,建议为空。点击第一个标志后,我收到预定义消息“无法找到任何内容...”,结果
我正在制作一个模拟 NHL 选秀彩票的程序,其中屏幕右侧应该有一个 JTextField,并且在左侧绘制弹跳的选秀球。我创建了一个名为 Ball 的类,它实现了 Runnable,并在我的主 Draf
这个问题已经有答案了: How can I calculate a time span in Java and format the output? (18 个回答) 已关闭 9 年前。 这是我的代码
我有一个 ASP.NET Web API 应用程序在我的本地 IIS 实例上运行。 Web 应用程序配置有 CORS。我调用的 Web API 方法类似于: [POST("/API/{foo}/{ba
我将用户输入的时间和日期作为: DatePicker dp = (DatePicker) findViewById(R.id.datePicker); TimePicker tp = (TimePic
放宽“邻居”的标准是否足够,或者是否有其他标准行动可以采取? 最佳答案 如果所有相邻解决方案都是 Tabu,则听起来您的 Tabu 列表的大小太长或您的释放策略太严格。一个好的 Tabu 列表长度是
我正在阅读来自 cppreference 的代码示例: #include #include #include #include template void print_queue(T& q)
我快疯了,我试图理解工具提示的行为,但没有成功。 1. 第一个问题是当我尝试通过插件(按钮 1)在点击事件中使用它时 -> 如果您转到 Fiddle,您会在“内容”内看到该函数' 每次点击都会调用该属
我在功能组件中有以下代码: const [ folder, setFolder ] = useState([]); const folderData = useContext(FolderContex
我在使用预签名网址和 AFNetworking 3.0 从 S3 获取图像时遇到问题。我可以使用 NSMutableURLRequest 和 NSURLSession 获取图像,但是当我使用 AFHT
我正在使用 Oracle ojdbc 12 和 Java 8 处理 Oracle UCP 管理器的问题。当 UCP 池启动失败时,我希望关闭它创建的连接。 当池初始化期间遇到 ORA-02391:超过
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve
引用这个plunker: https://plnkr.co/edit/GWsbdDWVvBYNMqyxzlLY?p=preview 我在 styles.css 文件和 src/app.ts 文件中指定
为什么我的条形这么细?我尝试将宽度设置为 1,它们变得非常厚。我不知道还能尝试什么。默认厚度为 0.8,这是应该的样子吗? import matplotlib.pyplot as plt import
当我编写时,查询按预期执行: SELECT id, day2.count - day1.count AS diff FROM day1 NATURAL JOIN day2; 但我真正想要的是右连接。当
我有以下时间数据: 0 08/01/16 13:07:46,335437 1 18/02/16 08:40:40,565575 2 14/01/16 22:2
一些背景知识 -我的 NodeJS 服务器在端口 3001 上运行,我的 React 应用程序在端口 3000 上运行。我在 React 应用程序 package.json 中设置了一个代理来代理对端
我面临着一个愚蠢的问题。我试图在我的 Angular 应用程序中延迟加载我的图像,我已经尝试过这个2: 但是他们都设置了 src attr 而不是 data-src,我在这里遗漏了什么吗?保留 d
我是一名优秀的程序员,十分优秀!