0
如何可以调用从方法URL或NSString的另一类我怎样才能调用URL从另一个类
1类
+ (NSURL *)createRequestURLWithChannel:(NSString *)channelName {
NSString *sName = [channelName stringByReplacingOccurrencesOfString:@"_" withString:@"-"];
NSString *channelvideo = [NSString stringWithFormat:@"%@", sName];
return [NSURL URLWithString:url];
}
2类
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (PlayRowIndex == indexPath.row) {
NSURL *videoURL = [NSURL URLWithString:channelvideo];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:nil];
} else if (StopRowIndex == indexPath.row) {
// Row stop
} else if (RowIndex == indexPath.row) {
// Row 3
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
我想呼叫URL channelvideo
从类别1中的方法(createRequestURLWithChannel
)并且在类别2中使用它的方法(tableView
)
你需要将class 1的标题导入到class 2中,然后创建class 1的实例 –
** NSNotificationCenter ** –
这是一个实例方法s o你不需要创建任何对象。你可以简单地通过导入你的类来使用这个方法。 #import“Class1.h” 并使用这样的方法.. NSURL * url = [Class1 createRequestURLWithChannel @“ChannelName”]; –