2014-11-27 11 views
5

Uygulamayı aşağıdaki kodla oluşturdum. IOS7 ile çalışıyor, ancak iOS8 ile çalıştığımda aşağıdaki hatayı atar.[UINavigationController setGoalName:]: örneğin 0x7964e2c0 adresine iletilen tanınmayan seçici

[UINavigationController setGoalName:]: unrecognized selector sent to instance 0x7964e2c0 

Benim firstViewcontroller.m

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

GoalDetailsViewController *goalsDetailsViewController = segue.destinationViewController; 
NSLog(@"%@",[NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]]); 
goalsDetailsViewController.goalName = @"Exercise Daily"; 

} 

Benim GoalDetailsViewController.h önceden

@interface GoalDetailsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> 

@property (nonatomic) NSString *goalName; 

teşekkürler.

+0

Hazırlamasında "HazırlıkForSegue: gönderen:" yazın ve 'destinationViewController' öğesini inceleyin. Muhtemelen GoalDetailsViewController'ın gerçek bir örneği değildir ve bu nedenle setGoalName: selektörünü tanımayacaktır. Tahminimce, iOS 8 size beklemediğiniz başka bir görünüm denetleyicisi gönderiyor. – ravron

+0

Görünen o ki 'targetDetailsViewController' bir UINavigationController. –

cevap

10

Hedef görünümünüzün UINAvigationController'ın bir alt sınıfı olduğu anlaşılıyor.

bu deneyin: basitçe destinationViewController bunun üzerine bir özelliği ayarlamak denemeden önce sen bekliyorsanız Çeşidi olduğundan emin olmak için olurdu bu kilitlenme işlemek için

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

GoalDetailsViewController *goalsDetailsViewController = [(UINavigationController*)segue.destinationViewController topViewController]; 
NSLog(@"%@",[NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]]); 
goalsDetailsViewController.goalName = @"Exercise Daily"; 

} 
+0

YourViewController * Controller = (YourViewController *) [segue.destinationViewController topViewController]; – IKKA

3

kolay yolu. Böyle bir şey:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    GoalDetailsViewController *goalsDetailsViewController = segue.destinationViewController; 
    NSLog(@"%@",[NSString stringWithFormat:@"%@", [[self.arrCategoryTitle objectAtIndex:indexPath.row] objectAtIndex:indexOfCategory]]); 

    if ([segue.destinationViewController isKindOfClass:[GoalDetailsViewController class]]) { 
     GoalDetailsViewController *goalsDetailsViewController = segue.destinationViewController; 
     goalsDetailsViewController.goalName = @"Exercise Daily"; 
    } 
} 

Bu değişiklik destinationViewController gibi ele alıp önce nazik GoalDetailsViewController arasında olmasını sağlar.

İlgili konular