我有兩個分離的類FirstController和SecondController,用故事板創建。問題是我想調用SecondController.m中的方法,FROM FirstController。例如。 :IOS:在另一個控制器中調用方法
SecondController.m
-(void)myMethod:(CGPoint)pt {...} // It's important that there is a paramterer
FirstController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Call myMethod
}
如何做到這一點的最簡單的方法?
更新: 我想使用的通知從 'aBilal17' 鏈接:
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateLeftTable"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(checkRes:) name:@"updateLeftTable" object:nil];
(..)
-(void)checkRes:(NSNotification *)notification
{
if ([[notification name] isEqualToString:@"updateLeftTable"])
{
[myMethod ?
}
}
在其他類:
[[NSNotificationCenter defaultCenter] postNotificationName:@"updateLeftTable" object:self];
但現在,如何使用這個來傳遞我的CGPoint參數?
你看了什麼?關於這種在stackoverflow上的事情有數百個問題。 – Popeye 2013-04-09 14:53:10
除非您正在討論委託協議或通知,否則您可能希望在MVC中引入更多模型。您通常不應該從其他控制器調用代碼。 – 2013-04-09 15:30:20