TableView rows hide and show as Bool function
As shown in image, initially I need to hide last 2 rows (my profile and update profile) in my table view when the user fills the form accessed via the "Become a merchant" row. I need to hide the "Become a Merchant" row and show the last two rows. This is done by Bool function(true/false).
How could I do this?
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var isMerchantProfile: Bool = UserDefaults.standard.bool(forKey: "isFillMerchant")
if isMerchantProfile == true {
return 4
}
return arrdata.count
}
ios swift uitableview
add a comment |
As shown in image, initially I need to hide last 2 rows (my profile and update profile) in my table view when the user fills the form accessed via the "Become a merchant" row. I need to hide the "Become a Merchant" row and show the last two rows. This is done by Bool function(true/false).
How could I do this?
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var isMerchantProfile: Bool = UserDefaults.standard.bool(forKey: "isFillMerchant")
if isMerchantProfile == true {
return 4
}
return arrdata.count
}
ios swift uitableview
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30
add a comment |
As shown in image, initially I need to hide last 2 rows (my profile and update profile) in my table view when the user fills the form accessed via the "Become a merchant" row. I need to hide the "Become a Merchant" row and show the last two rows. This is done by Bool function(true/false).
How could I do this?
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var isMerchantProfile: Bool = UserDefaults.standard.bool(forKey: "isFillMerchant")
if isMerchantProfile == true {
return 4
}
return arrdata.count
}
ios swift uitableview
As shown in image, initially I need to hide last 2 rows (my profile and update profile) in my table view when the user fills the form accessed via the "Become a merchant" row. I need to hide the "Become a Merchant" row and show the last two rows. This is done by Bool function(true/false).
How could I do this?
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var isMerchantProfile: Bool = UserDefaults.standard.bool(forKey: "isFillMerchant")
if isMerchantProfile == true {
return 4
}
return arrdata.count
}
ios swift uitableview
ios swift uitableview
edited Nov 22 '18 at 0:44
rmaddy
244k27324386
244k27324386
asked Nov 21 '18 at 15:22
AleeshaAleesha
668
668
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30
add a comment |
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30
add a comment |
3 Answers
3
active
oldest
votes
I think first you need to be able to establish whether or not the user has filled the form out. Maybe using an enum type with different user levels to display different content. So maybe something like this.
enum UserType {
case basic
case merchant
}
Then when you load the data into the table view just switch on UserType and load the proper data set. That would allow you to use this implementation elsewhere throughout your app as well if you needed to add/remove data/views based on user type. So your menus would look something like this:
let basicUserMenu = ["Home", "Orders", "Change Password", "Log Out", "Become Merchant"]
let merchantUserMenu = basicUserMenu + ["My Profile", "Update Profile"]
And then your table view implementation would look something like this where userType is your stored UserType enum value. By default it would be .basic but after the user fills out the form successfully changes to .merchant
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch userType {
case .basic:
return basicUserMenu.count
case .merchant:
return merchantUserMenu.count
}
}
Then do the same thing for cellForTowAtIndexPath
add a comment |
Remove / add the rows you want to show from your data array and then use the table view functions insertRowsAt
/ deleteRowsAt
. Do bulk updates using the performBatchUpdates
function.
Refer to the UITableView documentation.
I would also recommend in this case using an enum
to define your rows and rather than raw strings representing the titles of the rows.
e.g. (inside your view controller class is fine)
enum Row {
case home, orders, changePassword, logout, becomeMerchant, myProfile, updateProfile
var title: String {
switch self {
case .home:
return NSLocalizedString("Home", comment: "Row title")
// … etc
}
}
}
Then it's a bit easier to find the rows you want to remove / where to insert your rows and keep your code clean.
add a comment |
I would adjust the data/array when reloadTable is called to match the expected behavior.
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "My Profile", "Update Profile"] and then later:
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"] when you want this to show.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2fstackoverflow.com%2fquestions%2f53415247%2ftableview-rows-hide-and-show-as-bool-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think first you need to be able to establish whether or not the user has filled the form out. Maybe using an enum type with different user levels to display different content. So maybe something like this.
enum UserType {
case basic
case merchant
}
Then when you load the data into the table view just switch on UserType and load the proper data set. That would allow you to use this implementation elsewhere throughout your app as well if you needed to add/remove data/views based on user type. So your menus would look something like this:
let basicUserMenu = ["Home", "Orders", "Change Password", "Log Out", "Become Merchant"]
let merchantUserMenu = basicUserMenu + ["My Profile", "Update Profile"]
And then your table view implementation would look something like this where userType is your stored UserType enum value. By default it would be .basic but after the user fills out the form successfully changes to .merchant
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch userType {
case .basic:
return basicUserMenu.count
case .merchant:
return merchantUserMenu.count
}
}
Then do the same thing for cellForTowAtIndexPath
add a comment |
I think first you need to be able to establish whether or not the user has filled the form out. Maybe using an enum type with different user levels to display different content. So maybe something like this.
enum UserType {
case basic
case merchant
}
Then when you load the data into the table view just switch on UserType and load the proper data set. That would allow you to use this implementation elsewhere throughout your app as well if you needed to add/remove data/views based on user type. So your menus would look something like this:
let basicUserMenu = ["Home", "Orders", "Change Password", "Log Out", "Become Merchant"]
let merchantUserMenu = basicUserMenu + ["My Profile", "Update Profile"]
And then your table view implementation would look something like this where userType is your stored UserType enum value. By default it would be .basic but after the user fills out the form successfully changes to .merchant
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch userType {
case .basic:
return basicUserMenu.count
case .merchant:
return merchantUserMenu.count
}
}
Then do the same thing for cellForTowAtIndexPath
add a comment |
I think first you need to be able to establish whether or not the user has filled the form out. Maybe using an enum type with different user levels to display different content. So maybe something like this.
enum UserType {
case basic
case merchant
}
Then when you load the data into the table view just switch on UserType and load the proper data set. That would allow you to use this implementation elsewhere throughout your app as well if you needed to add/remove data/views based on user type. So your menus would look something like this:
let basicUserMenu = ["Home", "Orders", "Change Password", "Log Out", "Become Merchant"]
let merchantUserMenu = basicUserMenu + ["My Profile", "Update Profile"]
And then your table view implementation would look something like this where userType is your stored UserType enum value. By default it would be .basic but after the user fills out the form successfully changes to .merchant
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch userType {
case .basic:
return basicUserMenu.count
case .merchant:
return merchantUserMenu.count
}
}
Then do the same thing for cellForTowAtIndexPath
I think first you need to be able to establish whether or not the user has filled the form out. Maybe using an enum type with different user levels to display different content. So maybe something like this.
enum UserType {
case basic
case merchant
}
Then when you load the data into the table view just switch on UserType and load the proper data set. That would allow you to use this implementation elsewhere throughout your app as well if you needed to add/remove data/views based on user type. So your menus would look something like this:
let basicUserMenu = ["Home", "Orders", "Change Password", "Log Out", "Become Merchant"]
let merchantUserMenu = basicUserMenu + ["My Profile", "Update Profile"]
And then your table view implementation would look something like this where userType is your stored UserType enum value. By default it would be .basic but after the user fills out the form successfully changes to .merchant
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch userType {
case .basic:
return basicUserMenu.count
case .merchant:
return merchantUserMenu.count
}
}
Then do the same thing for cellForTowAtIndexPath
answered Nov 21 '18 at 17:56
Tyler RolfeTyler Rolfe
10919
10919
add a comment |
add a comment |
Remove / add the rows you want to show from your data array and then use the table view functions insertRowsAt
/ deleteRowsAt
. Do bulk updates using the performBatchUpdates
function.
Refer to the UITableView documentation.
I would also recommend in this case using an enum
to define your rows and rather than raw strings representing the titles of the rows.
e.g. (inside your view controller class is fine)
enum Row {
case home, orders, changePassword, logout, becomeMerchant, myProfile, updateProfile
var title: String {
switch self {
case .home:
return NSLocalizedString("Home", comment: "Row title")
// … etc
}
}
}
Then it's a bit easier to find the rows you want to remove / where to insert your rows and keep your code clean.
add a comment |
Remove / add the rows you want to show from your data array and then use the table view functions insertRowsAt
/ deleteRowsAt
. Do bulk updates using the performBatchUpdates
function.
Refer to the UITableView documentation.
I would also recommend in this case using an enum
to define your rows and rather than raw strings representing the titles of the rows.
e.g. (inside your view controller class is fine)
enum Row {
case home, orders, changePassword, logout, becomeMerchant, myProfile, updateProfile
var title: String {
switch self {
case .home:
return NSLocalizedString("Home", comment: "Row title")
// … etc
}
}
}
Then it's a bit easier to find the rows you want to remove / where to insert your rows and keep your code clean.
add a comment |
Remove / add the rows you want to show from your data array and then use the table view functions insertRowsAt
/ deleteRowsAt
. Do bulk updates using the performBatchUpdates
function.
Refer to the UITableView documentation.
I would also recommend in this case using an enum
to define your rows and rather than raw strings representing the titles of the rows.
e.g. (inside your view controller class is fine)
enum Row {
case home, orders, changePassword, logout, becomeMerchant, myProfile, updateProfile
var title: String {
switch self {
case .home:
return NSLocalizedString("Home", comment: "Row title")
// … etc
}
}
}
Then it's a bit easier to find the rows you want to remove / where to insert your rows and keep your code clean.
Remove / add the rows you want to show from your data array and then use the table view functions insertRowsAt
/ deleteRowsAt
. Do bulk updates using the performBatchUpdates
function.
Refer to the UITableView documentation.
I would also recommend in this case using an enum
to define your rows and rather than raw strings representing the titles of the rows.
e.g. (inside your view controller class is fine)
enum Row {
case home, orders, changePassword, logout, becomeMerchant, myProfile, updateProfile
var title: String {
switch self {
case .home:
return NSLocalizedString("Home", comment: "Row title")
// … etc
}
}
}
Then it's a bit easier to find the rows you want to remove / where to insert your rows and keep your code clean.
edited Nov 21 '18 at 15:35
answered Nov 21 '18 at 15:28
shimshim
4,04064679
4,04064679
add a comment |
add a comment |
I would adjust the data/array when reloadTable is called to match the expected behavior.
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "My Profile", "Update Profile"] and then later:
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"] when you want this to show.
add a comment |
I would adjust the data/array when reloadTable is called to match the expected behavior.
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "My Profile", "Update Profile"] and then later:
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"] when you want this to show.
add a comment |
I would adjust the data/array when reloadTable is called to match the expected behavior.
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "My Profile", "Update Profile"] and then later:
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"] when you want this to show.
I would adjust the data/array when reloadTable is called to match the expected behavior.
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "My Profile", "Update Profile"] and then later:
var arrdata = ["Home", "Orders", "Change Password", "Log Out", "Become A Merchant", "My Profile", "Update Profile"] when you want this to show.
answered Nov 21 '18 at 15:29
Alex BaileyAlex Bailey
459517
459517
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2fstackoverflow.com%2fquestions%2f53415247%2ftableview-rows-hide-and-show-as-bool-function%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
Possible duplicate of How to insert new cell into UITableView in Swift
– shim
Nov 21 '18 at 15:30