-1
我想在City.m控制器中創建的AddCity.m控制器中使用委託方法。該方法是我的程序不在委託方法內
City.m
- (void)EditCityController:(id)controller didEditItem:(id)item
{
if(item)
{
NSDictionary *d = (NSDictionary *)item;
[self.model addNewCity:[d valueForKey:@"cityName"] forProvince:self.ro inMayor:[d valueForKey:@"mayorName"] inPopulation:[[d valueForKey:@"population"]intValue] inYearEstablished:[[d valueForKey:@"yearEstablished"]intValue]];
[self.model saveChanges];
}
// Dismiss the modal view controller
[controller dismissViewControllerAnimated:YES completion:nil];
}
City.h
@interface Cities :
UITableViewController<NSFetchedResultsControllerDelegate, EditCityDelegate>
然後在AddCity.hi有
@protocol EditCityDelegate;
@interface AddCity : UIViewController<UITextFieldDelegate>
@property (nonatomic, assign) id <EditCityDelegate> delegate;
@protocol EditCityDelegate <NSObject>
- (void) EditCityController:(id)controller didEditItem:(id)item;
@end
我從AddCity.m調用它(目前正在嘗試取消按鈕)。
- (IBAction)cancel:(id)sender {
[self.delegate EditCityController:self didEditItem:nil];
}
當我把一個斷點發生的事情是它擊中self.delegate線,但它並沒有進入EditCityController方法是什麼我做錯了City.m controller.Any想法?
你可以檢查'self.delegate'的值嗎?如果它爲零,Objective-C將默默跳過方法調用。 – dpassage
不,那似乎不是問題 – user2433194
你是如何在AddCity.m中初始化self.delegate的? – Joshua