- (void) tapGesture: (id)sender
{
UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
NSInteger userID = gesture.view.tag;
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
OthersProfile *vc = (OthersProfile*)[storyboard instantiateViewControllerWithIdentifier:@"othersprofile"];
NSString *strUserID = [NSString stringWithFormat:@"%ld", (long)userID];
vc.userID = strUserID;
[self.viewController.navigationController pushViewController:vc
animated:YES];
}
它曾经与Xcode 8 / Swift 3一起使用,但似乎Xcode 9和swift 4存在问题。
我找不到属性userID错误。
在Swift文件中:
var userID : String = ""
override func viewDidLoad() {
print(userID) //no value here
}
任何有想法的人?
答案 0 :(得分:2)
请改为尝试:
@objc var userID : String = "
将Swift代码暴露给Objective-C的规则在Swift 4中已经更改了。因此,您的代码在Swift 3中没问题,因此您面临的混乱;)
答案 1 :(得分:0)
您需要解决的另一个问题是如何访问控制器:
这是因为当您尝试设置它时vc.user
为nil,将一个变量添加到swift控制器并设置它而不是`vc.user.text
vc.yourVariable = strUserID;
[self.viewController.navigationController pushViewController:vc
animated:YES];
然后在viewDidAppear中,您将能够使用此变量
进行设置 @IBOutlet var user: UILabel!
public var yourVariable: String = ""
override func viewDidLoad() {
user.text = yourVariable
print(user.text!) //should be value
}