我有2个ViewControllers: 1)MainViewController 2)WebViewController
和带有标识符ShowWeb的segue。
MainViewController包含从一个类名称AppView启动的多个NSObjects实例:NSObject
在每个NSObject内部都有一个UIButton,我希望它能够执行show类型的segue。如何执行segue?
对不起,如果我的问题重复了,但我昨天搜索了大约4个小时的所有网站,并没有找到确切的方式,并知道我正在使用swift。
我会更清楚地解释一下:
class MainViewController: {
var appviews = [AppView]()
override func viewDidLoad() {
super.viewDidLoad()
for i = 0; i < MyApps.count ; ++i{
var appview = AppView()
appview = AppView(sourceView: AppsScrollView, AppIconURLString: AppPicture,AppName: "MyAppName", LoadedDescription:"Very Good Application", ObjectNo: i, LinkButtonString: "http://stackoverflow.com/posts/28288611")
appviews.append(appview)
}
}
//
// AppView.swift
// Arabic Apps
//
// Created by d-point on 3/24/1436 AH.
// Copyright (c) 1436 e-Dever. All rights reserved.
//
import UIKit
class AppView: NSObject {
var BackView = UIView()
var AppIconView = UIImageView()
var TitleLabel = UILabel()
var DescriptionLabel = UILabel()
var LinkIcon = UIImageView()
var AppNo:Int!
var DescriptionText:String!
var AppTitleName:String!
let originView:UIView!
let LinkImage = UIImage(named: "HyperLink.png")
var LinkButton = UIButton.buttonWithType(UIButtonType.System) as UIButton
let TitleHeight:CGFloat = 20.0
let DescHeight:CGFloat = 40.0
let BackViewHeight:CGFloat = 100.0
let AppIconSize:CGFloat = 80.0
let Inset:CGFloat = 10.0
let BackgroundAlpha:CGFloat = 0.5
let LinkButtonSize:CGFloat = 35.0
var LinkButtonPath = String()
var MyViewController = UIViewController()
override init() {
super.init ()
}
init(sourceView:UIView, AppIconURLString: String? , AppName: String,LoadedDescription: String , ObjectNo: Int , LinkButtonString: NSString){
super.init()
originView = sourceView
AppIconView.image = UIImage(named: "App-Icon-Copy.png")
if var Icon = AppIconURLString {
ImagesLoader.downloadImage(NSURL(string: Icon), handler: {image, error in
self.AppIconView.image = image
})}
AppTitleName = AppName
DescriptionText = LoadedDescription
AppNo = ObjectNo
LinkButtonPath = LinkButtonString
setupAppView()
}
func setupAppView() {
//SetupBackView
BackView.frame = CGRectMake(Inset,
Inset + (CGFloat(AppNo) * (BackViewHeight + 15)),
originView.bounds.size.width - (Inset * 2),
BackViewHeight)
BackView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(BackgroundAlpha)
BackView.layer.cornerRadius = 20.0
BackView.clipsToBounds = false
originView.addSubview(BackView)
//SetupAppIconView
AppIconView.frame = CGRectMake(BackView.bounds.size.width - AppIconSize - Inset, Inset, AppIconSize, AppIconSize)
AppIconView.layer.cornerRadius = 15.0
AppIconView.layer.borderWidth = 2.0
AppIconView.layer.borderColor = UIColor.whiteColor().CGColor
AppIconView.clipsToBounds = true
BackView.addSubview(AppIconView)
//SetupTitleView
TitleLabel.frame = CGRectMake(Inset, Inset, BackView.bounds.size.width - AppIconSize - Inset*6, TitleHeight)
TitleLabel.text = AppTitleName
TitleLabel.textColor = UIColor.blackColor()
TitleLabel.textAlignment = NSTextAlignment.Center
//TitleLabel.font = UIFont(name: TitleLabel.font.fontName, size: 18.0)
TitleLabel.font = UIFont.boldSystemFontOfSize(16.0)
BackView.addSubview(TitleLabel)
//SetupDescriptionLabel
DescriptionLabel.frame = CGRectMake(Inset, TitleHeight, BackView.bounds.size.width - AppIconSize - Inset*6, DescHeight)
DescriptionLabel.text = DescriptionText
DescriptionLabel.textColor = UIColor.blackColor()
DescriptionLabel.textAlignment = NSTextAlignment.Justified
BackView.addSubview(DescriptionLabel)
//SetupButtonView
//LinkButton
LinkButton.frame = BackView.bounds
LinkButton.addTarget(self, action:"GotoLinkURL:", forControlEvents:UIControlEvents.TouchUpInside)
LinkButton.tag = AppNo
BackView.addSubview(LinkButton)
}
func GotoLinkURL(sender:UIButton) {
var mainviewcontroller:MainViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("MainView") as MainViewController
mainviewcontroller.performSegueWithIdentifier("ShowWeb", sender: self)
}
}