这里我有与UItableVIEw部分相关的问题:
第一个问题:我有一个问题,我如何从多个部分启动数字0的UItableVIEw部分?
例如 :
我在UItableVIEw和numberOfSectionsIntableVIEw委托方法中有11个部分,我的部分首先从第11个部分开始,然后是0,1,2,3,4,5,6,7,8,9和10.
那我怎么能用0号开始我的节号然后照原样.
第二个问题:在TitleForheaderInSection委托方法中,tableVIEw的所有部分重复3次.并且在当前的VIEwController中,我向上或向下滚动UItableVIEw,然后在正常(0到11)部分显示UItableVIEw的这个正常部分,在重复第3部分之后显示.
例如 :
我使用NSLog(@“%d”,部分);在TitleForheaderInSection委托方法中,然后在控制台中显示输出,如下所示
控制台输出:
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] 112012-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] 02012-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] 12012-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] 22012-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] 32012-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] 42012-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] 52012-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] 62012-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] 72012-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] 82012-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] 92012-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] 102012-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,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委托方法的本质意味着您可以(并且应该)以这样的方式编写方法,即它们不依赖于调用单元格或节的顺序.永远不要依赖UI中的事件序列来管理您构建视图底层模型的方式.
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,我会感到惊讶,不要只依赖它调用一次.我认为表格视图可能会为表格的每个部分调用一次(可能需要做出类似于整个表格的高度以便滚动条的大小适当),然后再次对屏幕上可见的部分进行调整(实际显示节标题).
总结以上是内存溢出为你收集整理的iphone – 当我有多个部分时,如何用数字0启动我的UITableView部分?全部内容,希望文章能够帮你解决iphone – 当我有多个部分时,如何用数字0启动我的UITableView部分?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)