我正在嘗試從我的類中的類PYTimelineViewController
中檢索NSString
類型的變量。從另一個類中檢索變量 - 目標C
這裏我在做什麼:
在我rippleMake.m
/* SET OBJECT */
PYTimelineViewController *getRippleForVideo = [[PYTimelineViewController alloc] init];
/* ESTABLISH THE RIPPLE IT VIDEO FOR CHALLENGE VIDEO */
NSString *videoFor = [getRippleForVideo getchallengeForVideo];
NSLog(@"%@",videoFor);
在運行此,videoFor
返回null
。
在我PYTimelineViewController.h
@interface PYTimelineViewController : UITableViewController//<MWPhotoBrowserDelegate>
...
@property (nonatomic, strong) NSString *challengeForVideo;
-(NSString *)getchallengeForVideo;
- (void)setchallengeForVideo:(NSString*)challengeforVideo;
@end
我
PYTimelineViewController.m
-(IBAction)openRippleIt:(id)sender
{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
NSInteger rowOfTheCell = (indexPath.row + 1000); // ADD 1000 to get away from effecting other code
UIButton *button=(UIButton *)[self.view viewWithTag:rowOfTheCell];
NSString *btnTitle = [button currentTitle];
[self setchallengeForVideo:btnTitle];
NSLog(@"%@",[self getchallengeForVideo]); <--- This outputs exactly what I need.
[self performSegueWithIdentifier:@"moveTorippleIt" sender:self];
}
的.m
getter和setter
:
-(void) setchallengeForVideo:(NSString *)challengeforVideo
{
_challengeForVideo = challengeforVideo;
}
-(NSString *) getchallengeForVideo
{
return _challengeForVideo;
}
這是粗推動用戶對新ViewController
但中不應該是一個問題。
不知道爲什麼我無法檢索值,因爲一切似乎都已正確配置。特別是我的getters和setters。
建議,想法?
什麼時候被稱爲'openRippleIt'設置'challengeForVideo'? – Larme
請注意,getters和setters會爲您生成屬性。您可以完全刪除getchallengeForVideo和setchallengeForVideo:方法。 – drewag
@CrimsonChris在正確的軌道上,你需要以某種方式引用先前的'PYTimelineViewController'而不是創建一個新的。 – Aaron