現在、UITableView、より正確にはカスタムセルに問題があります。
さまざまなTableViewCellの表示を担当するテーブルビューコントローラー、たとえばControllerAを入手しました。これらのセルはカスタムセルであり、別のクラス、たとえばControllerCellで定義されています。各セルには、これらの情報ボタンの1つが含まれています(小さく、「i」が付いた丸い)。これらのボタンは、表示するものがある場合にのみ表示されます。
ControllerCellで、次の内容を定義します。
@property (nonatomic, retain) IBOutlet UIButton *infoButton;
@property (nonatomic, retain) IBOutlet UIAlertView *alert;
@property (nonatomic, retain) IBOutlet NSString *info;
- (IBAction)infoSupButton:(id)sender;
誰もがそうするように、@synthesisと同様に。次に、アラートで何が起こるかを定義します。
- (IBAction)infoSupButton:(id)sender {
alert = [[UIAlertView alloc] initWithTitle:@"Informations supplémentaires"
message:info
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
if (info != nil) {
[alert show];
}
}
そして、「initWithStyle」セクションでは、
[_infoButton addTarget:self action:@selector(infoSupButton:) forControlEvents:UIControlEventTouchUpInside];
それはセルの宣言のためでした。
それでは、ControllerAに焦点を当てましょう。
XMLファイルを解析して「info」データを取得しています。このデータは「infoButton」をクリックすると表示されます。このデータを取得してコンソールに表示できるため、これは実際には問題ではありません。
データが解析されたら、viewDidLoadセクションにNSMutableArrayを入力します。
tableInfoSup = [[NSMutableArray alloc] init];
次に、古典的な方法に従います。
-numberOfSectionsInTableView:(3セクション)-numberOfRowsInSection:(セクション0に8行、セクション1に4行、セクション2に4行)-cellForRowAtIndexPath:
3つの異なるセクションがあり、異なる情報を持つセルが表示されています。cellForRowAtIndexメソッドでは、次のようにします。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"ExerciceTableCell";
ControllerCell *cell = (ControllerCell *)[tableView dequeueReusableCellWithIdentifier:exerciceTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ExerciceTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (indexPath.section == 0) {
[...]
if ([[tableInfoSup objectAtIndex:indexPath.row] isEqualToString:@""]) {
[cell.infoButton setHidden:YES];
cell.info = nil;
}
else {
cell.info = [tableInfoSup objectAtIndex:indexPath.row];
}
}
if (indexPath.section == 1) {
[...]
if ([[tableInfoSup objectAtIndex:indexPath.row+8] isEqualToString:@""]) {
[cell.infoButton setHidden:YES];
cell.info = nil;
}
else {
cell.info = [tableInfoSup objectAtIndex:indexPath.row+8]; //got the 8 rows from section 0;
}
}
if (indexPath.section == 2) {
[...]
if ([[tableInfoSup objectAtIndex:indexPath.row+12] isEqualToString:@""]) {
[cell.infoButton setHidden:YES];
cell.info = nil;
}
else {
cell.info = [tableInfoSup objectAtIndex:indexPath.row+12]; //got the 8 rows from section 0, + 4 rows from section 1
}
}
return cell;
}
さて、問題は、画面が初めて表示されたときにすべてが正常に動作していることです。小さな「i」ボタンのあるセルが表示され、良好なUIAlertViewが表示されますが、他のいくつかのセルではボタンが表示されません...それは正常。しかし、数回スクロールすると、「i」ボタンが消え始めます。理由はわかりません。
誰かアイデアはありますか?ありがとう :-)