2014-04-08 28 views
0

我在IOS 7應用程序中使用SWRevealViewController類。IOS顯示視圖 - 在另一個UIViewController中觸發函數

我有一個前視圖(MainHP_TableViewController)和一個後視圖(messagesTVController),左側視圖顯示在右側滑動以顯示消息。

我的問題是,我需要在關閉揭密(基本上消息計數需要更新)時在前視圖中觸發一個方法。

我發現在SWRevealViewController一個動作的事件觸發重視,並有建立的方法我的主視圖控制器如下接受它 -

swRevealViewController.m

MainHP_TableViewController *mhp = [[MainHP_TableViewController alloc] initWithNibName:nil bundle:nil]; 
    [mhp readyBtn]; 

MainHP_TableViewController.m

- (void)readyBtn{ 

    NSLog(@"passed back"); 

    _btnNo = 1; 

    // NSLog(@"Value of hello = %@", _btnNo); 

    //[self.tableView reloadData]; 
} 

會發生什麼情況是滑動操作事件起作用,並且傳回的消息出現在控制檯中 - _btnNo var更改爲1 - 但是如果我取消註釋NSLog行或重新加載數據行(上面的屏幕截圖),應用程序崩潰。 。在控制檯沒有任何錯誤令人討厭..

我可以調用MainHP_TableViewController本身的一個按鈕相同的方法,所有工作正常 - 所以我猜它的某種權限問題與從另一個方法調用的方法控制器?但它讓我很頭疼 - 所以任何提示都會非常受歡迎!

回答

2

我認爲應該更好地使用NSNotificationCenter; 在前面視圖 - 控制你可以像在viewDidLoad註冊觀察員:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(notificationRecived:) 
              name:@"reloadData" 
              object:nil]; 

,並把選擇方法:

- (void)notificationRecived:(NSNotification *)notification { 
    if([notification.name isEqualToString:@"reloadData"]) { 
    // Do stuff here 
    // [self.tableView reloadData]; 
    } 
} 

在後視圖 - 控制你可以簡單地張貼通知:

[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:nil userInfo:nil]; 
+0

酷@woulstoke - 這是完美的 - 感謝您的幫助.. – Dancer

相關問題