The Storyboard: http://s7.directupload.net/images/140717/z5hwmezv.png
Hey guys,
Ive got an app that recursively triggers a the same tableview controller (lets say there are files and folders in it) until you trigger a file instead of a folder. When a file is clicked, it jumps into the GLKit View Controller.
Now I want to resize the tableView programmatically, which wont work. I already got the window size, which I'm going to use for calculation the position and size of the tableView:
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
I tried different ways to change the size like the following, which dont change anything.
mainTableView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
It works If I programmatically create the mainTableView, but then my segue gets deleted and I did not found any solution to create a segue programmatically.
It would be great if you can help me to find a solution that works with a storyboard tableView.
Step 1: Add delegate UITableViewDataSource,UITableViewDelegate
#interface viewController: UIViewController<UITableViewDataSource,UITableViewDelegate>
{
UITableView *tableView;
}
Step 2:
-(void)viewDidLoad
{
tableView=[[UITableView alloc]init];
tableView.frame = CGRectMake(10,30,320,400);
tableView.dataSource=self;
tableView.delegate=self;
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
[tableView reloadData];
[self.view addSubview:tableView];
}
Step 3: Properties for tableview
//-- For table sections
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
//-- For no of rows in table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//-- Table header height if needed
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50;
}
//-- Assign data to cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath] ;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[your_array objectAtIndex:indexPath.row]; ***(or)*** cell.textLabel.text = #"Hello";
return cell;
}
//-- Operation when touch cells
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Your custom operation
}
Looking at your pic makes me think your CustomerListVC is a UITableView subclass which means the tableview is the root view and if you are using a UINavigationController based flow then you can't resize the root view readily.
What you can do is place the UITableView in a container and manipulate its constraints from the controller.
first change
class CustomerListVC : UITableViewController
to
class CustomerListVC : UIViewController
next throw away the Customer List instance in Interface Builder and drag in a new UIViewController instance instead. Xcode doesn't like you changing the base class of its stock objects.
make the new UIViewController instance a CustomerListVC type FileOwner and drag a UITableView into the content view.
Set edge constraints and add outlets to the constraints in your view controller.
From there play with the table as you see fit. e.g
-(void)squishAtBottomLeftAnimated:(BOOL)animate {
CGFloat animateTime = animate? 0.5:0;
[UIView animateWithDuration:animateTime animations:^{
self.topEdgeConstraint.constant = 400;
self.bottomEdgeConstraint.constant = 5;
self.leadingEdgeConstraint.constant = 5;
self.trailingEdgeConstraint.constant = 200;
[self.view layoutIfNeeded];
}];
}
Related
I am working on a feature in an app where the user can tap on some attribute about a car (such as its color) and a list of different colors will be shown.
This is just part of the page. The whole page consists of different views and view controllers all wrapped together in a vertical stack view, but I do not think that is what is causing the animation issues here. This is the overall structure of the page:
UIScrollView
UIStackView
UIViewController
UIView
UITableViewController <-- this is the class being shown in this question
...
But for this question, I am just showing the section of the page where this table is.
So I am having an issue with the animation of the table as can be seen in the gifs later on. The way this section is structured is that it is a UITableViewController subclass that takes in a model (a title and a list of car colors) and it displays a different table section for each model element.
Each section has a section header, which is the part where the user taps. It shows the color and it shows a preview image. When that is tapped, a table row is added to the table for that section and that change is animated. The table view row that is added to the table contains a UICollectionView that lays out content horizontally. This idea came from the WWDC 2010 - Mastering Table Views video.
It is basically something like this. Each section header is the interactive part where you can tap on it. Then the row that is shown in the section has a collection view.
* SectionHeader
* SectionHeader
* Table row containing a UICollectionView
* SectionHeader
The problem I am having is that the animation is behaving in a strange manner, as can be seen in the following images.
The first image shows what happens if a row is expanded that has other rows below it. In this case, it appears as if the other two rows in the table are essentially floating above the content of the new row that is animating in. Additionally, at the bottom of the section, those two rows come in from the bottom as the previous two rows sort of get vertically squished until they are gone.
The second animation here shows the bottom row expanding. This one is closer to what I want, except that the row content still briefly shows at the top of the row above the divider (which is the section footer of the previous section).
Here is my code for the table view controller class.
MyAttributeTableViewController.h
#import <UIKit/UIKit.h>
#import "MyAttribute.h"
#import "MyAttributeTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
#interface MyAttributeTableViewController : UITableViewController<MyAttributeDelegate>
//this represents each section of the table. It contains a title (color, for example), a selected value (red),
//and a list of possible values that will be used to display the collection view when the section is expanded.
#property (strong, nonatomic) NSArray<MyAttribute *> *modelAttributes;
#end
NS_ASSUME_NONNULL_END
MyAttributeTableViewController.m
#import "MyAttributeTableViewController.h"
#import "MyAttributeTableHeaderView.h"
#import "MyAttributeTableViewCell.h"
#interface MyAttributeTableViewController ()
//this keeps track of which sections are expanded. Initially, all sections start out
//not expanded. Then, upon tap, a section's expanded status is toggled here. This is
//used by the table view's data source to know when to display a row in a section.
#property (strong, nonatomic) NSMutableArray<NSNumber *> *itemsExpanded;
#end
#implementation MyAttributeTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = UITableViewAutomaticDimension;
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionFooterHeight = CGFLOAT_MIN;
//this xib file only contains the UICollectionView that is shown upon expanding the section.
//There is nothing that interesting in this file, but I have some screenshots of the
//attribute inspector for this xib file after this code.
[self.tableView registerNib:[UINib nibWithNibName:#"MyAttributeTableViewCell" bundle:nil] forCellReuseIdentifier:#"MyAttributeTableViewCell"];
[self.tableView registerClass:[MyAttributeTableHeaderView class] forHeaderFooterViewReuseIdentifier:#"AttributeHeaderView"];
[self.tableView invalidateIntrinsicContentSize];
}
- (void)setAttributeOptions:(NSArray<MyAttribute *> *)modelAttributes {
self->_modelAttributes = modelAttributes;
self->_itemsExpanded = [NSMutableArray arrayWithCapacity:[self->_modelAttributes count]];
for (NSUInteger x=0; x<[self->_modelAttributes count]; x++) {
[self->_itemsExpanded addObject:#NO];
}
[self.tableView reloadData];
}
//TODO: is this necessary?
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
self.preferredContentSize = self.tableView.contentSize;
}
#pragma mark - MyAttributeDelegate
- (void)twister:(MyAttributeTableViewCell *)cell didSelectItemAtIndex:(NSInteger)index {
UITableViewHeaderFooterView *headerView = [self.tableView headerViewForSection:cell.sectionIndex];
if ([headerView isKindOfClass:[MyAttributeTableHeaderView class]]) {
MyAttributeTableHeaderView *twisterHeaderView = (MyAttributeTableHeaderView *)headerView;
twisterHeaderView.twister.selectedSwatchIndex = [NSNumber numberWithInteger:index];
[twisterHeaderView updateAttributeIfNeeded];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.modelAttributes.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.itemsExpanded[section].boolValue ? 1 : 0;
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
MyAttributeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyAttributeTableViewCell" forIndexPath:indexPath];
MyAttribute *twister = self.modelAttributes[indexPath.section];
cell.swatches = twister.swatches;
NSNumber *swatchCellHeight = cell.swatchCellHeight;
if (swatchCellHeight) {
return swatchCellHeight.floatValue + 20.0f; //TODO: need to get this from the collection view
}
return 352.0f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == self.modelAttributes.count) {
return CGFLOAT_MIN;
}
return 1.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyAttributeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyAttributeTableViewCell" forIndexPath:indexPath];
MyAttribute *twister = self.modelAttributes[indexPath.section];
cell.swatches = twister.swatches;
cell.sectionIndex = indexPath.section;
cell.delegate = self;
if ([twister isSwatchSelected]) {
NSInteger selectedIndex = twister.selectedSwatchIndex.integerValue;
[cell.collectionView selectItemAtIndexPath:[NSIndexPath indexPathForItem:selectedIndex inSection:0] animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];
}
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
MyAttributeTableHeaderView *cell = (MyAttributeTableHeaderView *)[tableView dequeueReusableHeaderFooterViewWithIdentifier:#"AttributeHeaderView"];
if (cell.gestureRecognizers.count == 0) {
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleSection:)];
[cell addGestureRecognizer:tapRecognizer];
}
cell.sectionIndex = section;
cell.expanded = self.itemsExpanded[section].boolValue;
cell.twister = self.modelAttributes[section];
return cell;
}
- (void)toggleSection:(UITapGestureRecognizer *)gesture {
MyAttributeTableHeaderView *destinationView = ((MyAttributeTableHeaderView *)gesture.view);
BOOL expanded = [destinationView toggleExpanded];
self.itemsExpanded[destinationView.sectionIndex] = [NSNumber numberWithBool:expanded];
UIView *viewToLayout = self.tableView;
while ([viewToLayout superview]) {
viewToLayout = viewToLayout.superview;
}
if (expanded) {
[UIView beginAnimations:#"expandTableAnimationId" context:nil];
[UIView setAnimationDuration:1.0f];
[CATransaction begin];
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:#[[NSIndexPath indexPathForRow:0 inSection:destinationView.sectionIndex]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
[viewToLayout layoutIfNeeded];
[CATransaction commit];
[UIView commitAnimations];
} else {
[UIView beginAnimations:#"collapseTableAnimationId" context:nil];
[UIView setAnimationDuration:1.0f];
[CATransaction begin];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:#[[NSIndexPath indexPathForRow:0 inSection:destinationView.sectionIndex]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
[viewToLayout layoutIfNeeded];
[CATransaction commit];
[UIView commitAnimations];
}
}
#end
MyAttributeTableViewCell
Does anyone know what I am doing wrong or how to get these animations to look correct (no doubling of rows and no collection view showing up above the row when it is animating in)? Or if you know a better way to handle this that might be less complicated, I am open to that as well. I am just trying to have a list of expandable sections, where each section has a collection view of selectable items.
Hi i am new for ios and in my app i have created one UITableView and i have set background image for UITableViewcell but image not filling the whole width of screen as like below screen. Why this problem is occuring?
I mean UITableViewCell left and right sides gap is coming images is not filling whole cell width.
please help me someone
my code:-
#import "TableViewController.h"
#interface TableViewController ()
{
UITableView * tableList;
TableCell * Cell;
}
#end
#implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
tableList = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height) style:UITableViewStylePlain];
tableList.delegate = self;
tableList.dataSource = self;
tableList.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableList];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"MyCell";
Cell = (TableCell *)[tableList dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (Cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TableCell" owner:self options:nil];
Cell = [nib objectAtIndex:0];
}
//UIImageView *imageBackground = [[UIImageView alloc] init];
if (indexPath.row == 0) {
Cell.backGroundImage.image = [UIImage imageNamed:#"cell_top.png"];
} else if (indexPath.row == 9) {
Cell.backGroundImage.image = [UIImage imageNamed:#"cell_bottom.png"];
} else {
Cell.backGroundImage.image = [UIImage imageNamed:#"cell_middle.png"];
}
//imageBackground.contentMode = UIViewContentModeScaleToFill;
//Cell.backgroundView = imageBackground;
return Cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44.0;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ([cell respondsToSelector:#selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:#selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
if ([cell respondsToSelector:#selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
#end
Try to set the layoutMargins property of the cells and the UITableView to UIEdgeInsetsZero.
- (void) viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
tableList.layoutMargins = UIEdgeInsetsZero;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
[...]
Cell.layoutMargins = UIEdgeInsetsZero;
return Cell;
}
Also check for the contentMode of the UIImageview.
Cell.backGroundImage.contentMode = UIViewContentModeScaleAspectFill;
try set contentInset on Left = 0
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
Use Debug View Hierarchy to figure out UITableView, UITableViewCell or UIImage is not filling the whole width of screen
http://www.raywenderlich.com/98356/view-debugging-in-xcode-6
Please check your "TableCell" in the storyboard. Did you select custom insets option for your custom cell?
Rather than setting up your table view with code, you want to do this in a storyboard. Then you'll want to use auto layout to connect constraints from the table view to the view controller's view. There are lots of tutorials available to teach you how to do this. Learning this will make things much easier in the long run.
Change the name of your tableList property to tableView. That will make more sense to other developers (including yourself in the future), since that's what it is (a UITableView instance).
Your cell is named Cell with a capital C, but you don't want to name properties with capital letters. Also, it doesn't need to be a class property the way it's being used. Remove it from the #interface section.
Coding Guidelines for Cocoa
Remove the -numberOfSectionsInTableView: method. The default is 1, so you don't need code to return the default value.
Instead of -dequeueReusableCellWithIdentifier:, use -dequeueReusableCellWithIdentifier:forIndexPath:. Then you won't need to follow it with a test to see if a cell was returned (it always will be). You'll need to register your nib with -registerNib:forCellReuseIdentifier:. Or better yet, just design it in the storyboard.
It appears that your custom table view cell has a UIImageView named backGroundImage. That should be added as a subview to the cell's backgroundView property (which you'll need to create - the view, not the property, which is already part of UITableViewCell). Set the image view's autoresizingMask so it will resize with the backgroundView:
- (void)awakeFromNib
{
[super awakeFromNib];
self.backgroundView = [[UIView alloc] initWithFrame:self.bounds];
self.backGroundImage.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.backGroundImage.frame = self.backgroundView.bounds;
[self.backgroundView addSubview:self.backGroundImage];
}
Remove the -tableView:heightForRowAtIndexPath: method. You only want to use this if you return different values. The default row height is 44.0, so you don't need to do anything else.
I have this UITableView, made in code ,and when i see it first time, the cells size that i read are wrong-hence the icons on the cells calculated wrong and are very small.
Than , when i start scrolling,every cell i scroll through ,its icons (on this cell),becomes bigger and get their right size,and i see also the small icons too, so i have for each cell a small icon and a big icon,where i should only have the big.
Why is that happens ? (this view also has some collection view inside it)
//tabel view
frm.origin.y=self.frame.size.height-openY;
tableView = [[UITableView alloc]initWithFrame:frm style:UITableViewStylePlain];
tableView.delegate=self;
tableView.dataSource=self;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
[self addSubview:tableView];
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [actionsMenus count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.frame.size.height/5.0;
}
- (UITableViewCell *)tableView:(UITableView *)ttableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"Cell";
UITableViewCell *tcell= [ttableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
NSLog(#"%f", tcell.frame.size.height );
if (tcell == nil)
{
tcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *kind=[actionsMenus objectAtIndex:indexPath.row];
NSString *icon=[NSString stringWithFormat:#"%#%d.png",kind,colorIndex];
//icon
UIImage *image=[UIImage imageNamed:icon];
UIImageView *view=[[UIImageView alloc] initWithFrame:CGRectMake(tcell.frame.size.width/2.0-0.8*tcell.frame.size.height/2.0, 0, 0.8*tcell.frame.size.height,0.8*tcell.frame.size.height)];
view.image=image;
[tcell addSubview:view];
return tcell;
}
If you're creating the table in viewDidLoad, I think the UITableView delegate methods are being called before the view's auto-layout is complete; so setting the heightForRowAtIndexPath: to
return self.frame.size.height/5.0;
uses the frame of the view pre-auto-layout to calculate the row height. If you absolutely need heightForRowAtIndexPath: to be dependent on the view's height though, perhaps add the table as a subview after view's layout is complete. For example, instead of adding it in your viewDidLoad, add it in viewDidLayoutSubviews, ex:
- (void) viewDidLayoutSubviews {
//table view
frm.origin.y=self.frame.size.height-openY;
tableView = [[UITableView alloc]initWithFrame:frm style:UITableViewStylePlain];
tableView.delegate=self;
tableView.dataSource=self;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
[self addSubview:tableView];
}
I have two tableviews in one view controller.
One is there in the interface builder and the other i have created dynamically using the below code in the viewDidLoad() method.
// Creating the view for placing the dynamic tableview
-(UIView *) createAndAddMenuView :(float) viewHeight
{
UIView *myView = [[UIView alloc] init];
myView.backgroundColor = [UIColor blueColor];
CGRect coord = myView.frame;
coord.origin.x = -255;
coord.origin.y = 0;
coord.size.width = 255;
coord.size.height = viewHeight;
[myView setFrame:coord];
return myView;
}
-(void) addMenuItemsTable{
UITableView *dynamicTable=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 255, self.navigationController.view.frame.size.height) style:UITableViewStylePlain];
dynamicTable.delegate=self;
dynamicTable.dataSource=self;
dynamicTable.tag = 20;
//[dynamicTable reloadData];
[menuView addSubview:dynamicTable];
}
Both these two tableviews have delegate and datasource set to self. The second dynamic tableview is added to a view and placed on the left hidden side with x = -255.
When I click on the button in the navigation bar i am moving "menuView" view to the screen and the other static tableview out of the screen just like the Facebook app.
I am using this code for moving the menuView back and forth.
-(void) toggleMainView :(UITableView *) mytableView withMenuView : (UIView * )menuView{
NSLog(#"TAG %d",mytableView.tag);
CGRect destination = mytableView.frame;
NSLog(#"XX %f",destination.origin.x);
if (destination.origin.x > 0) {
destination.origin.x = 0;
} else {
destination.origin.x += 255;
}
NSLog(#"ORG X = %f", destination.origin.x );
[UIView animateWithDuration:0.25 animations:^{
[self showMenu:menuView];
mytableView.frame = destination;
} completion:^(BOOL finished) {
mytableView.userInteractionEnabled = !(destination.origin.x > 0);
}];
}
-(void)showMenu :(UIView *)menuView{
CGRect coord = menuView.frame;
NSLog(#"Width = %f, x = %f",coord.size.width, coord.origin.x);
if(coord.origin.x < 0){
coord.origin.x = 0;
}else{
coord.origin.x = -255;
}
[menuView setFrame:coord];
}
But when I am NOT setting the second tableview Datasource then only this code is working.
I have no idea why this is happening.
ie. When I comment out this line
dynamicTable.dataSource=self;
Then only when I click the button the first tableview is moving out of the screen.
All these times the dynamic one will move back and forth in the screen.
When the DS is not commented the first (static tableview) will not move and Second (dynamic one) will move.
This is my first iPhone application.
if you are using 2 tableview or 1 tableview try to set tag values for it with two different values suppose for table1 tag is 50 and for table2 tag is 60 then the code in tableview delegates and datasource should be like below.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(tableView.tag==50) // if you have 2 different objects for tableviews then you can also use like this if(tableView == tableviewObjc1)
{
// tableview1 info
}
else
{
// tableview2 info
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
for (UIView *view in cell.contentView.subviews) {
[view removeFromSuperview];
}
if(tableView.tag==50)
{
// tableview1 info
}
else
{
// tableview2 info
}
return cell;
}
You can use any custom control that suits your requirement
from cocoacontrols one of them is
MVYSideMenu
You don't require to add two tableview in one ViewController
You should try below approach:
STEPS:
Add two Prototype cells to storybaord
Make two custom cell class subclassing UITableViewCell and design your cell storyboard or via code
cellForRowAtIndexPath: initialize cell according to requirement and set it datasource and delegate methods accordingly
I have a programmatically implemented tableView, in the grouped style.
All I am getting is the gray pinstripes when it should be populated. So it is loading, but not ... something...
What more is necessary?
If no more, then where else ought I look?
Also, how can I make the background color of the table the same as the cell's white color?
- (void)loadView {
[super loadView];
UITableView *view = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame style:UITableViewStyleGrouped];
[view setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
self.view = view;
[view reloadData];
}
Is viewDidLoad necessary?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
Thank you,
Morkrom
You have to provide your tableView with data.
For staters you'll need to define a dataSource. Its common to just use your viewController as the dataSource.
// in the .h find something similar and add <UITableViewDataSource>
#interface ViewController : UIViewController <UITableViewDataSource>
then when you make the tableView.
view.datasource = self;
Then you'll need to provide the data itself. Implement these methods:
#pragma mark - UITableView Datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
[cell.textLabel setText:#"A Cell"];
return cell;
}
Those methods will create 3 sections each with 3 rows. All the cells will just say A Cell. This is the basis for all tableViews. Just customize the data :)
You need to set dataSource and delegate properties for your table view so it will be able to pull data from them:
UITableView *view = ...
view.dataSource = self;
view.delegate = self;
have protocol in .h file and attach delegate and source with file owner