У меня есть проблема, когда я показываю предупреждение, а затем после нажатия кнопки некоторые методы должны запускаться, но ни один из них не работает.
- (void)insertNewObject //Works fine
{
//AlertView is a subclass of UIAlertView I created.
AlertView *al = [AlertView alloc];
al = [al initWithTitle:@"title" message:@"message" delegate:[self view] cancelButtonTitle:@"cencel" okButtonTitle:@"ok"];
[al.titlebox becomeFirstResponder];
//[view setAlertViewStyle:UIAlertViewStylePlainTextInput];
[al show];
} /Till here everything works fine.
Весь приведенный ниже код не работает.Или они работают, я просто не знаю, потому что они не запускаются.
//This method does no run al all.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex2
{
if(buttonIndex2 == 0)
{
_buttonIndex = buttonIndex2;
[self showAbortAlert];
} else
{
_buttonIndex = buttonIndex2;
[self addObject];
}
}
- (void)addObject
{
if(_buttonIndex == 1) {
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
// If appropriate, configure the new managed object.
// Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
[newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
//[newManagedObject setValue:<#(id)#> forKey:<#(NSString *)#>];
//[newManagedObject setValue:<#(id)#> forKey:<#(NSString *)#>];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
} else {
[self showAbortAlert];
}
}
- (void)showAbortAlert
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Action Aborted" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert setAlertViewStyle:UIAlertViewStyleDefault];
[alert show];
}
Нет ошибок компиляции.Заранее спасибо!