これが私のテーブルビューの外観です。
これが私のコードです ViewController.hを下にスクロールするとこうなります
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSMutableArray *items ;
}
@property (nonatomic,retain) NSMutableArray *items ;
@end
ViewController.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
すべてのセクションの最初の行の画像を表示したいだけです。ロード時の出力は問題ありませんが、ビューをスクロールすると最初の画像が消えます。この問題を解決するにはどうすればよいですか?? どんな助けでも大歓迎です。よろしくお願いします。