私はUILongPressGestureRecognizerでアラートを表示しています。私が直面する問題は、アラートを1回クリックするだけで解除する必要がある間に、アラートを解除するたびに3回クリックする必要があることです。なぜこのUIAlertViewを3回却下する必要がありますか?
そして、これによる異常行動に、エントリはコアデータに重複します。..
私が使用していたコードは下の通りです:cellForRowAtIndexPathで
:(無効で
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// NSString * cellValue;
if (tableView == listTable) {
cellValue = [listVehicles objectAtIndex:indexPath.row];
} else { // handle search results table view
cellValue = [filteredListItems objectAtIndex:indexPath.row];
}
static NSString *CellIdentifier = @"vlCell";
VehicleListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(@"Cell Created");
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"VehicleListCell" owner:nil options:nil];
for (id currentObject in nibObjects) {
if ([currentObject isKindOfClass:[VehicleListCell class]]) {
cell = (VehicleListCell *)currentObject;
}
}
UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableCellPressed:)];
pressRecongnizer.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:pressRecongnizer];
[pressRecongnizer release];
}
cell.textLabel.font = [UIFont systemFontOfSize:10];
[[cell ignition] setImage:[UIImage imageNamed:@"ignition.png"]];
[[cell direction] setImage:[UIImage imageNamed:@"south.png"]];
cell.licPlate.text = cellValue;
NSLog(@"cellvalue for cellforRow: %@", cell.licPlate.text);
return cell;
}
)tableCellPressed:(UILongPressGestureRecognizer *)認識メソッド
- (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer {
VehicleListCell* cell = (VehicleListCell *)[recognizer view];
cellValueForLongPress = cell.licPlate.text;
NSLog(@"cell value: %@", cellValueForLongPress);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil] ;
[alert addButtonWithTitle:@"Add to Favourites"];
[alert addButtonWithTitle:@"Take to Map"];
[alert show];
}
アラートビュー方式で:
-(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alert buttonTitleAtIndex:buttonIndex];
NSManagedObjectContext *context = [app managedObjectContext];
Favouritesdata * favourites = [NSEntityDescription insertNewObjectForEntityForName:@"Favouritesdata" inManagedObjectContext:context];
if([title isEqualToString:@"Add to Favourites"])
{
NSLog(@"Added to favourites.");
NSLog(@"cellValueForLongPress: %@", cellValueForLongPress);
if (cellValueForLongPress <= 0) {
NSLog(@"There is no value to save");
}
else {
favourites.licenseplate = cellValueForLongPress;
}
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
else if([title isEqualToString:@"Take to Map"])
{
NSLog(@"Go to MapView");
}
NSError *error;
if (![context save:&error]) {
NSLog(@"Error Occured");}
}
何が問題になりますか?
あなたはコードスニペットで私を助けることができるしてください –
例を更新しました... –
のthnx @Simonリー:)その解決 –