UILongPressGestureRecognizer에 경고를 표시하고 있습니다. 문제는 내가 클릭 할 때마다 세 번 클릭하여 알림을 해제해야하며 알림은 한 번의 클릭으로 무시해야한다는 것입니다. 왜이 UIAlertView를 세 번 닫아야합니까?
그리고 인해 비정상적인 행동에 항목이 핵심 데이터에서 중복 얻을
..내가 사용하고있는 코드는 아래로 : 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");}
}
어떤 문제가있을 수 있습니까?
당신은 코드와 함께 나를 도울 수 바랍니다 –
통해 UR의 내 많은 저장된 ... –
thnx @ 사이먼 리 : 그 해결 –