这就是我的表格视图的外观。
这是我的代码 当我向下滚动 ViewController.h时会发生这种情况
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray *items ;
}
@property (nonatomic,retain) NSMutableArray *items ;
@end
视图控制器.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize items;
- (void)viewDidLoad
{
[super viewDidLoad];
items = [[NSMutableArray alloc] init];
[items addObject:@"bla bla bla"];
[items addObject:@"rikifhdif bla bla"];
[items addObject:@"bla sdfkndskfnlk bla"];
[items addObject:@"sdf,nsdmf bla bla"];
[items addObject:@"sdjkfhksd bla bla"];
[items addObject:@"dkfhkusd bla bla"];
[items addObject:@"bla sdfjknskdjf bla"];
[items addObject:@"kiidrfjifig jjojdjfgdfgjjdjsjkhksidfl"];
[items addObject:@"mksjdhf ysdgjg bla"];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma tableview logic
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 6;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
{
return @"Title0";
}
else if(section == 1)
{
return @"Title1";
}
else if(section == 2)
{
return @"Title2";
}
if(section == 3)
{
return @"Title3";
}
else if(section == 4)
{
return @"Title4";
}
else
{
return @"Title5";
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) {
return 3;
}
if (section==1) {
return 1;
}
if (section==2) {
return 2;
}
if (section==3) {
return 2;
}
if (section==4) {
return 1;
}
if (section==5) {
return 1;
}
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [items objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:@"Star.jpg"];
switch (indexPath.section) {
case 0:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
case 1:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
case 2:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
case 3:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
case 4:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
case 5:
if (indexPath.row==1) {
[[cell imageView] setHidden:YES];
}
if (indexPath.row==2) {
[[cell imageView] setHidden:YES];
}
break;
default:
break;
}
return cell;
//}
}
- (void)dealloc {
[items release], items = nil;
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
只想显示每个部分的第一行的图像。加载时输出正常,但是当我滚动视图时,第一个图像消失了。我该如何解决这个问题?任何帮助,将不胜感激。提前谢谢了。