Initiating Child ViewController from UIStoryBoard in iOS
up vote
0
down vote
favorite
I'm trying to use inheritance in UIViewController
where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.
I cannot use XIB file separately instead of storyboard because it has static UITableViewCells
.
So here is how I'm managing it currently using object_setClass
method in SWIFT:
Parent Class:
class MeetingViewController: UITableViewController {
private(set) var project: CDProject?
private(set) var meeting: CDMeeting?
static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
meetingVC.project = project
meetingVC.meeting = meeting
return meetingVC
}
}
Child Class-1:
class MeetingInfoViewController: MeetingViewController {
static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
object_setClass(meetingVC, MeetingInfoViewController.self)
return meetingVC as! MeetingInfoViewController
}
}
Child Class-2:
class MeetingCreateViewController: MeetingViewController {
static func initWith(project: CDProject) -> MeetingCreateViewController {
let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
object_setClass(meetingVC, MeetingCreateViewController.self)
return meetingVC as! MeetingCreateViewController
}
}
This is working very fine, not any issue; but I'm just curious if:
1 there's any other way to handle this scenario?
2 this approach has any side-effects?
3 this can be improved somehow?
Also feel free to point out other things than initialisation!
swift ios inheritance
add a comment |
up vote
0
down vote
favorite
I'm trying to use inheritance in UIViewController
where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.
I cannot use XIB file separately instead of storyboard because it has static UITableViewCells
.
So here is how I'm managing it currently using object_setClass
method in SWIFT:
Parent Class:
class MeetingViewController: UITableViewController {
private(set) var project: CDProject?
private(set) var meeting: CDMeeting?
static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
meetingVC.project = project
meetingVC.meeting = meeting
return meetingVC
}
}
Child Class-1:
class MeetingInfoViewController: MeetingViewController {
static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
object_setClass(meetingVC, MeetingInfoViewController.self)
return meetingVC as! MeetingInfoViewController
}
}
Child Class-2:
class MeetingCreateViewController: MeetingViewController {
static func initWith(project: CDProject) -> MeetingCreateViewController {
let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
object_setClass(meetingVC, MeetingCreateViewController.self)
return meetingVC as! MeetingCreateViewController
}
}
This is working very fine, not any issue; but I'm just curious if:
1 there's any other way to handle this scenario?
2 this approach has any side-effects?
3 this can be improved somehow?
Also feel free to point out other things than initialisation!
swift ios inheritance
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to use inheritance in UIViewController
where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.
I cannot use XIB file separately instead of storyboard because it has static UITableViewCells
.
So here is how I'm managing it currently using object_setClass
method in SWIFT:
Parent Class:
class MeetingViewController: UITableViewController {
private(set) var project: CDProject?
private(set) var meeting: CDMeeting?
static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
meetingVC.project = project
meetingVC.meeting = meeting
return meetingVC
}
}
Child Class-1:
class MeetingInfoViewController: MeetingViewController {
static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
object_setClass(meetingVC, MeetingInfoViewController.self)
return meetingVC as! MeetingInfoViewController
}
}
Child Class-2:
class MeetingCreateViewController: MeetingViewController {
static func initWith(project: CDProject) -> MeetingCreateViewController {
let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
object_setClass(meetingVC, MeetingCreateViewController.self)
return meetingVC as! MeetingCreateViewController
}
}
This is working very fine, not any issue; but I'm just curious if:
1 there's any other way to handle this scenario?
2 this approach has any side-effects?
3 this can be improved somehow?
Also feel free to point out other things than initialisation!
swift ios inheritance
I'm trying to use inheritance in UIViewController
where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB.
I cannot use XIB file separately instead of storyboard because it has static UITableViewCells
.
So here is how I'm managing it currently using object_setClass
method in SWIFT:
Parent Class:
class MeetingViewController: UITableViewController {
private(set) var project: CDProject?
private(set) var meeting: CDMeeting?
static func initWith(project: CDProject?, meeting: CDMeeting?) -> MeetingViewController {
let storyboard = UIStoryboard(name: "Meeting", bundle: nil)
let meetingVC = storyboard.instantiateViewController(withIdentifier: "MeetingVCId") as! MeetingViewController
meetingVC.project = project
meetingVC.meeting = meeting
return meetingVC
}
}
Child Class-1:
class MeetingInfoViewController: MeetingViewController {
static func initWith(meeting: CDMeeting) -> MeetingInfoViewController {
let meetingVC = MeetingViewController.initWith(project: nil, meeting: meeting)
object_setClass(meetingVC, MeetingInfoViewController.self)
return meetingVC as! MeetingInfoViewController
}
}
Child Class-2:
class MeetingCreateViewController: MeetingViewController {
static func initWith(project: CDProject) -> MeetingCreateViewController {
let meetingVC = MeetingViewController.initWith(project: project, meeting: nil)
object_setClass(meetingVC, MeetingCreateViewController.self)
return meetingVC as! MeetingCreateViewController
}
}
This is working very fine, not any issue; but I'm just curious if:
1 there's any other way to handle this scenario?
2 this approach has any side-effects?
3 this can be improved somehow?
Also feel free to point out other things than initialisation!
swift ios inheritance
swift ios inheritance
asked Nov 20 at 16:29
D4ttatraya
274113
274113
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f208079%2finitiating-child-viewcontroller-from-uistoryboard-in-ios%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown