我有一個UINavigationController
與UITableViewController
作爲根控制器。 UINavigationController
位於UIPopoverController
之內。 UITableViewController
包含UITableViewCell
(具有UISwitch
)和UITableViewCell
(具有UITableViewCellAccessoryDisclosureIndicator
),當點擊時加載另一個UITableView
。UITableView內的UISwitch
我的問題是,當在UISwitch
上滑動然後點擊其他單元格時,不會調用didSelectRowAtIndexPath
。如果我再次點擊被調用。如果我點擊UISwitch
,而不是刷卡,沒有任何問題。
該問題僅在iOS4上。在iOS5上效果很好!
我的cellForRowAtIndexPath方法是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier1 = @"Cell1";
static NSString *CellIdentifier2 = @"Cell2";
// Configure the cell...
NSUInteger row = [indexPath row];
UITableViewCell *cell = nil;
switch (row) {
case 0: {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [controllers objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryNone;
UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 11, 400, 30)];
passwordTextField.adjustsFontSizeToFitWidth = YES;
passwordTextField.placeholder = @"Richiesta";
passwordTextField.keyboardType = UIKeyboardTypeDefault;
passwordTextField.secureTextEntry = YES;
passwordTextField.tag = 100;
[passwordTextField addTarget:self action:@selector(passwordChanged:) forControlEvents:UIControlEventEditingChanged];
passwordTextField.text = password;
[cell addSubview:passwordTextField];
[passwordTextField release];
break;
}
case 1: {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [controllers objectAtIndex:row];
cell.accessoryType = UITableViewCellAccessoryNone;
UITextField *pinTextField = [[UITextField alloc] initWithFrame:CGRectMake(160, 11, 400, 30)];
pinTextField.adjustsFontSizeToFitWidth = YES;
pinTextField.placeholder = @"Richiesta";
pinTextField.keyboardType = UIKeyboardTypeDefault;
pinTextField.secureTextEntry = YES;
pinTextField.tag = 101;
[pinTextField addTarget:self action:@selector(pinChanged:) forControlEvents:UIControlEventEditingChanged];
pinTextField.text = aspin;
[cell addSubview:pinTextField];
[pinTextField release];
break;
}
case 2: {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier2] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
UITableViewController *controller = [controllers objectAtIndex:row];
cell.textLabel.text = controller.title;
cell.detailTextLabel.text = @"Busta Crittografica P7M (CAdES)";
envelopeType = cell.detailTextLabel.text;
break;
}
case 3: {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
}
cell.textLabel.text = @"Dichiaro di aver preso visione del documento, di sottoscriverne il contenuto e di essere consapevole della validità legale della firma apposta";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.numberOfLines = 5;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
//add a switch
UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchview addTarget:self action:@selector(declarationChanged:) forControlEvents:UIControlEventValueChanged];
switchview.on = declaration;
cell.accessoryView = switchview;
[switchview release];
break;
}
}
return cell;
}
而且我didSelectRowAtIndexPath方法的方法是:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
switch (row) {
case 0: {
[[[tableView cellForRowAtIndexPath:indexPath] viewWithTag:100] becomeFirstResponder];
break;
}
case 1: {
[[[tableView cellForRowAtIndexPath:indexPath] viewWithTag:101] becomeFirstResponder];
break;
}
case 2: {
((CheckListController *)[self.controllers objectAtIndex:2]).contentSizeForViewInPopover = self.view.bounds.size;
self.contentSizeForViewInPopover = self.view.bounds.size;
[self.navigationController pushViewController:[self.controllers objectAtIndex:2]
animated:YES];
break;
}
default:
break;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
這是一個非常棘手的問題,所以我需要你的幫助!
謝謝。
您能提供* cellForRowAtIndexPath:*和* didSelectRowAtIndexPath:*的代碼嗎?你使用兩個不同的標識符來創建兩個單元格(我看* CellIdentifier1 *)? – 2012-03-15 09:47:55
我編輯了我的問題。 – Giorgio 2012-03-15 10:14:32
你是什麼意思與刷卡和點擊* UISwicth *?對我來說,選擇你的可選單元沒有區別。 – 2012-03-15 12:04:14