UITableviewCell height according to In side another UITableviewCell height
up vote
0
down vote
favorite
{
MainTitle 1
{
Subtitle 1
( item 1
item 2
item 3 )
},
{
MainTitle 2
{
Subtitle 2
( item 1
item 2
item 3)
}
}
There is JSON data format that I have to display in UITableview
. The data is restaurant's menu. I create Table 1
for MainTitle
display and Table 1
cell inside another UITableview Table 2
for Subtitle and item
Subtitle
set as header and item
as row.
Tableview cell height is dynamic so I set it UITableViewAutomaticDimension
for both tableview. Table 1
cell height is set according to inside it Table 2
height. Table 2
is not scrollable, it's height is according to content height.
So, I want to set Table 1 cell
height after loading Table 2
all data.
objective-c uitableview ios-autolayout
add a comment |
up vote
0
down vote
favorite
{
MainTitle 1
{
Subtitle 1
( item 1
item 2
item 3 )
},
{
MainTitle 2
{
Subtitle 2
( item 1
item 2
item 3)
}
}
There is JSON data format that I have to display in UITableview
. The data is restaurant's menu. I create Table 1
for MainTitle
display and Table 1
cell inside another UITableview Table 2
for Subtitle and item
Subtitle
set as header and item
as row.
Tableview cell height is dynamic so I set it UITableViewAutomaticDimension
for both tableview. Table 1
cell height is set according to inside it Table 2
height. Table 2
is not scrollable, it's height is according to content height.
So, I want to set Table 1 cell
height after loading Table 2
all data.
objective-c uitableview ios-autolayout
I think nested table view isn't a good idea. You should try to handle them with only 1UITableView
– trungduc
Nov 20 at 4:42
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
{
MainTitle 1
{
Subtitle 1
( item 1
item 2
item 3 )
},
{
MainTitle 2
{
Subtitle 2
( item 1
item 2
item 3)
}
}
There is JSON data format that I have to display in UITableview
. The data is restaurant's menu. I create Table 1
for MainTitle
display and Table 1
cell inside another UITableview Table 2
for Subtitle and item
Subtitle
set as header and item
as row.
Tableview cell height is dynamic so I set it UITableViewAutomaticDimension
for both tableview. Table 1
cell height is set according to inside it Table 2
height. Table 2
is not scrollable, it's height is according to content height.
So, I want to set Table 1 cell
height after loading Table 2
all data.
objective-c uitableview ios-autolayout
{
MainTitle 1
{
Subtitle 1
( item 1
item 2
item 3 )
},
{
MainTitle 2
{
Subtitle 2
( item 1
item 2
item 3)
}
}
There is JSON data format that I have to display in UITableview
. The data is restaurant's menu. I create Table 1
for MainTitle
display and Table 1
cell inside another UITableview Table 2
for Subtitle and item
Subtitle
set as header and item
as row.
Tableview cell height is dynamic so I set it UITableViewAutomaticDimension
for both tableview. Table 1
cell height is set according to inside it Table 2
height. Table 2
is not scrollable, it's height is according to content height.
So, I want to set Table 1 cell
height after loading Table 2
all data.
objective-c uitableview ios-autolayout
objective-c uitableview ios-autolayout
edited Nov 20 at 7:01
Mukesh
465316
465316
asked Nov 20 at 4:31
Rahul Parikh
1819
1819
I think nested table view isn't a good idea. You should try to handle them with only 1UITableView
– trungduc
Nov 20 at 4:42
add a comment |
I think nested table view isn't a good idea. You should try to handle them with only 1UITableView
– trungduc
Nov 20 at 4:42
I think nested table view isn't a good idea. You should try to handle them with only 1
UITableView
– trungduc
Nov 20 at 4:42
I think nested table view isn't a good idea. You should try to handle them with only 1
UITableView
– trungduc
Nov 20 at 4:42
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
You could use proper UITableView sections and rows. Add "MainTitle" as Table Section and MainTitle's "Items" as Section Rows.
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
add a comment |
up vote
0
down vote
I'd recommend using one single tableview as mentioned by @trungduc and @Raj D
You should be able to use a custom tableview cell to layout the items the way you want, and you can always use buttons for items that need to be clickable (i.e. if you need to click on the menu items and show another view controller).
Here's a basic mockup of what I mean:
You'll want to use a stack view within the cell and then dynamically generate the menu items based off your backing data model (this should allow it to obtain the correct intrinsic content size for UITableViewAutomaticDimension to size the cells correctly).
Here's an example of what I mean by dynamically adding the menu items when setting the submenu item of the custom cell:
- (void)setupMenuItemsStack:(NSArray <RPMenuItem *> *)menuItems {
for (UIView *subview in self.menuItemsStack.arrangedSubviews) {
[NSLayoutConstraint deactivateConstraints:subview.constraints];
[subview removeFromSuperview];
}
for (RPMenuItem *menuItem in menuItems) {
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeSystem];
[menuItemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setTitle:menuItem.title forState:UIControlStateNormal];
[self.menuItemsStack addArrangedSubview:menuItemButton];
}
}
Depending on how you're structuring your model, the tableview methods would look something along these lines:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menuList.menus.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] subMenus].count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] title];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RPMenuTableViewCell *cell = (RPMenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RPMenuCell" forIndexPath:indexPath];
RPSubMenu *subMenu = [[[self.menuList.menus objectAtIndex:indexPath.section] subMenus] objectAtIndex:indexPath.row];
[cell setSubMenu:subMenu];
return cell;
}
Where the menu list is a top level list of menus and it cascades down from there (i.e. menu list holds an array of menus, menus hold an array of submenus, submenus hold an array of menu items).
@property (strong, nullable) RPMenuList *menuList;
Adding the ability to expand and contract (accordion style) to show the menu items would probably be a nice touch as well:
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You could use proper UITableView sections and rows. Add "MainTitle" as Table Section and MainTitle's "Items" as Section Rows.
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
add a comment |
up vote
0
down vote
You could use proper UITableView sections and rows. Add "MainTitle" as Table Section and MainTitle's "Items" as Section Rows.
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use proper UITableView sections and rows. Add "MainTitle" as Table Section and MainTitle's "Items" as Section Rows.
You could use proper UITableView sections and rows. Add "MainTitle" as Table Section and MainTitle's "Items" as Section Rows.
answered Nov 20 at 7:11
Raj D
27110
27110
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
add a comment |
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
what about "Subtitle"
– Rahul Parikh
Nov 20 at 9:07
add a comment |
up vote
0
down vote
I'd recommend using one single tableview as mentioned by @trungduc and @Raj D
You should be able to use a custom tableview cell to layout the items the way you want, and you can always use buttons for items that need to be clickable (i.e. if you need to click on the menu items and show another view controller).
Here's a basic mockup of what I mean:
You'll want to use a stack view within the cell and then dynamically generate the menu items based off your backing data model (this should allow it to obtain the correct intrinsic content size for UITableViewAutomaticDimension to size the cells correctly).
Here's an example of what I mean by dynamically adding the menu items when setting the submenu item of the custom cell:
- (void)setupMenuItemsStack:(NSArray <RPMenuItem *> *)menuItems {
for (UIView *subview in self.menuItemsStack.arrangedSubviews) {
[NSLayoutConstraint deactivateConstraints:subview.constraints];
[subview removeFromSuperview];
}
for (RPMenuItem *menuItem in menuItems) {
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeSystem];
[menuItemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setTitle:menuItem.title forState:UIControlStateNormal];
[self.menuItemsStack addArrangedSubview:menuItemButton];
}
}
Depending on how you're structuring your model, the tableview methods would look something along these lines:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menuList.menus.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] subMenus].count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] title];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RPMenuTableViewCell *cell = (RPMenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RPMenuCell" forIndexPath:indexPath];
RPSubMenu *subMenu = [[[self.menuList.menus objectAtIndex:indexPath.section] subMenus] objectAtIndex:indexPath.row];
[cell setSubMenu:subMenu];
return cell;
}
Where the menu list is a top level list of menus and it cascades down from there (i.e. menu list holds an array of menus, menus hold an array of submenus, submenus hold an array of menu items).
@property (strong, nullable) RPMenuList *menuList;
Adding the ability to expand and contract (accordion style) to show the menu items would probably be a nice touch as well:
add a comment |
up vote
0
down vote
I'd recommend using one single tableview as mentioned by @trungduc and @Raj D
You should be able to use a custom tableview cell to layout the items the way you want, and you can always use buttons for items that need to be clickable (i.e. if you need to click on the menu items and show another view controller).
Here's a basic mockup of what I mean:
You'll want to use a stack view within the cell and then dynamically generate the menu items based off your backing data model (this should allow it to obtain the correct intrinsic content size for UITableViewAutomaticDimension to size the cells correctly).
Here's an example of what I mean by dynamically adding the menu items when setting the submenu item of the custom cell:
- (void)setupMenuItemsStack:(NSArray <RPMenuItem *> *)menuItems {
for (UIView *subview in self.menuItemsStack.arrangedSubviews) {
[NSLayoutConstraint deactivateConstraints:subview.constraints];
[subview removeFromSuperview];
}
for (RPMenuItem *menuItem in menuItems) {
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeSystem];
[menuItemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setTitle:menuItem.title forState:UIControlStateNormal];
[self.menuItemsStack addArrangedSubview:menuItemButton];
}
}
Depending on how you're structuring your model, the tableview methods would look something along these lines:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menuList.menus.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] subMenus].count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] title];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RPMenuTableViewCell *cell = (RPMenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RPMenuCell" forIndexPath:indexPath];
RPSubMenu *subMenu = [[[self.menuList.menus objectAtIndex:indexPath.section] subMenus] objectAtIndex:indexPath.row];
[cell setSubMenu:subMenu];
return cell;
}
Where the menu list is a top level list of menus and it cascades down from there (i.e. menu list holds an array of menus, menus hold an array of submenus, submenus hold an array of menu items).
@property (strong, nullable) RPMenuList *menuList;
Adding the ability to expand and contract (accordion style) to show the menu items would probably be a nice touch as well:
add a comment |
up vote
0
down vote
up vote
0
down vote
I'd recommend using one single tableview as mentioned by @trungduc and @Raj D
You should be able to use a custom tableview cell to layout the items the way you want, and you can always use buttons for items that need to be clickable (i.e. if you need to click on the menu items and show another view controller).
Here's a basic mockup of what I mean:
You'll want to use a stack view within the cell and then dynamically generate the menu items based off your backing data model (this should allow it to obtain the correct intrinsic content size for UITableViewAutomaticDimension to size the cells correctly).
Here's an example of what I mean by dynamically adding the menu items when setting the submenu item of the custom cell:
- (void)setupMenuItemsStack:(NSArray <RPMenuItem *> *)menuItems {
for (UIView *subview in self.menuItemsStack.arrangedSubviews) {
[NSLayoutConstraint deactivateConstraints:subview.constraints];
[subview removeFromSuperview];
}
for (RPMenuItem *menuItem in menuItems) {
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeSystem];
[menuItemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setTitle:menuItem.title forState:UIControlStateNormal];
[self.menuItemsStack addArrangedSubview:menuItemButton];
}
}
Depending on how you're structuring your model, the tableview methods would look something along these lines:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menuList.menus.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] subMenus].count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] title];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RPMenuTableViewCell *cell = (RPMenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RPMenuCell" forIndexPath:indexPath];
RPSubMenu *subMenu = [[[self.menuList.menus objectAtIndex:indexPath.section] subMenus] objectAtIndex:indexPath.row];
[cell setSubMenu:subMenu];
return cell;
}
Where the menu list is a top level list of menus and it cascades down from there (i.e. menu list holds an array of menus, menus hold an array of submenus, submenus hold an array of menu items).
@property (strong, nullable) RPMenuList *menuList;
Adding the ability to expand and contract (accordion style) to show the menu items would probably be a nice touch as well:
I'd recommend using one single tableview as mentioned by @trungduc and @Raj D
You should be able to use a custom tableview cell to layout the items the way you want, and you can always use buttons for items that need to be clickable (i.e. if you need to click on the menu items and show another view controller).
Here's a basic mockup of what I mean:
You'll want to use a stack view within the cell and then dynamically generate the menu items based off your backing data model (this should allow it to obtain the correct intrinsic content size for UITableViewAutomaticDimension to size the cells correctly).
Here's an example of what I mean by dynamically adding the menu items when setting the submenu item of the custom cell:
- (void)setupMenuItemsStack:(NSArray <RPMenuItem *> *)menuItems {
for (UIView *subview in self.menuItemsStack.arrangedSubviews) {
[NSLayoutConstraint deactivateConstraints:subview.constraints];
[subview removeFromSuperview];
}
for (RPMenuItem *menuItem in menuItems) {
UIButton *menuItemButton = [UIButton buttonWithType:UIButtonTypeSystem];
[menuItemButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[menuItemButton setTitle:menuItem.title forState:UIControlStateNormal];
[self.menuItemsStack addArrangedSubview:menuItemButton];
}
}
Depending on how you're structuring your model, the tableview methods would look something along these lines:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.menuList.menus.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] subMenus].count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [[self.menuList.menus objectAtIndex:section] title];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
RPMenuTableViewCell *cell = (RPMenuTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"RPMenuCell" forIndexPath:indexPath];
RPSubMenu *subMenu = [[[self.menuList.menus objectAtIndex:indexPath.section] subMenus] objectAtIndex:indexPath.row];
[cell setSubMenu:subMenu];
return cell;
}
Where the menu list is a top level list of menus and it cascades down from there (i.e. menu list holds an array of menus, menus hold an array of submenus, submenus hold an array of menu items).
@property (strong, nullable) RPMenuList *menuList;
Adding the ability to expand and contract (accordion style) to show the menu items would probably be a nice touch as well:
edited Nov 21 at 19:35
answered Nov 21 at 18:16
R4N
75224
75224
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53386278%2fuitableviewcell-height-according-to-in-side-another-uitableviewcell-height%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
I think nested table view isn't a good idea. You should try to handle them with only 1
UITableView
– trungduc
Nov 20 at 4:42