
我有arrayOne有3个项目和arrayTwo有4个项目,如何添加和显示它们的部分。
- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { if(section == 0) return resultArray.count; else return resultArray.count;}- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw { return 2;}- (Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForheaderInSection:(NSInteger)section{ NSLog(@"Number of Sections"); if(section == 0) return @"Section 1"; if(section == 1) return @"Section 2";}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"table Cell Data"); static Nsstring *CellIDentifIEr = @"Cell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellIDentifIEr]; } appDelegate = (MultipleDetailVIEwsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate]; if (indexPath.section==0) { appDelegate = (MultipleDetailVIEwsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate]; ObjectData *theCellData = [resultArray objectAtIndex:indexPath.row]; Nsstring *cellValue =theCellData.category; NSLog(@"Cell Values %@",cellValue); cell.textLabel.text = cellValue; return cell; } else { ObjectData *theCellData = [resultArray objectAtIndex:indexPath.row]; Nsstring *cellValue =theCellData.category; cell.textLabel.text = cellValue; return cell; }}解决方法 - (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw { return 2 ; } - (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { if (section==0) { return [array1 count]; } else{ return [array2 count]; } } - (Nsstring *)tableVIEw:(UItableVIEw *)tableVIEw TitleForheaderInSection:(NSInteger)section { if(section == 0) return @"Section 1"; else return @"Section 2"; } - (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath { static Nsstring *CellIDentifIEr = @"Cell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr]; if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleSubTitle reuseIDentifIEr:CellIDentifIEr]; } if (indexPath.section==0) { ObjectData *theCellData = [array1 objectAtIndex:indexPath.row]; Nsstring *cellValue =theCellData.category; cell.textLabel.text = cellValue; } else { ObjectData *theCellData = [array2 objectAtIndex:indexPath.row]; Nsstring *cellValue =theCellData.category; cell.textLabel.text = cellValue; } return cell; } 总结 以上是内存溢出为你收集整理的iphone – UITableView与多个部分全部内容,希望文章能够帮你解决iphone – UITableView与多个部分所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)