Change tableView:heightForRowAtIndexPath - ios

I'm a bit confused on how I go about changing the UITableViewCell. Is this correct?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 95;
}
If I need to explain more I can. Sorry if this is a dumb question, I'm new to iOS dev.

That code is fine, it is probably just not being called. You need to properly set the delegate property of the table view for this method to be called.
or
Since your heights are all the same, you can take a shortcut and set the rowHeight property of your table view.

this delegate will change the height of the table view cell

first check you have declared table view delegate in .h file or not..
No need of declaring table view with property..
UITableView *tableView;
declare like this..

set your table's datasource and delegate to File's owner from .xib.

Related

iCarousel View in a table cell view does not scroll at all

I put the iCarousel View in a table View and try to scroll the iCarousel, but the problem is it's not scrollable at all.
I can see iCarousel in the cell like following:
and I put iCarousel datasource and delegate in the tableView Controller, create a customer function to set the iCarousel datasource and delegate.
In the CustomTableViewCell I just define the setting delegate function:
- (void) setICarouselDataSourceDelegate: (id<iCarouselDelegate,iCarouselDataSource>)dataSourceDelegate {
self.carousel.dataSource = dataSourceDelegate;
self.carousel.delegate = dataSourceDelegate;
[self.carousel reloadData];
}
and in the MainTableView, I call the DataSourceDelegate in the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
First of all iCarousel is not any standarad View ... you should put link of the control that you're using
Second it seems like iCarousel is uses UIScrollView and UITableView is also derived from UIScrollView It's never a good idea to put a scrollview inside another scrollview.
This might be the reason why your table view is not scrolling.... BTW are you talking about horizontal scrollign or vertical scrolling ?
Currently I am using the iCarousel in Table View cell and it scrolls easily.
Just add standard view to cell in Storyboard.
In IB mark the class of that view to iCarousel.
Furthermore !ENABLE! user interaction on that view. (Maybe because of that you can't scroll the content inside the cell)
Implement separate datasource & delegate for every cell. (It is more clear which data are loading in the cell and also the cell itself can handle the data. You just pass the data to cell and it handles it accordingly.) - But it depends on you if you want to let one class to handle two separate control datasources & delegates :-)

Obtaining the UITableViewHeaderFooterView of a static UITableView

I have a Storyboard which contains a UITableViewController. The table view is static and contains two sections. The table view was setup entirely in IB (including the header and footer text of the table view sections) - I have not implemented any table view delegate methods in my view controller.
If I attempt to get a reference to the UITableViewHeaderFooterView for a given section it always returns nil.
UITableViewHeaderFooterView* header =[self.tableView headerViewForSection:0];
When I run the app I can see the header and footer text that I set in IB so I know those views are there. I just can't figure out how to access them programmatically.
Any help would be much appreciated,
CS
Actually you'll need to specify the table footer view, and pass it to the table view using its delegate.
For example, suppose you have defined a IBOutlet UIView named tableFooterView.
Then in the following delegate method, you can pass your tableFooterView to your table view:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default or specified footer height
{
return self.tableFooterView;
}
Also you'll need to implement the following method to set the height of the table footer view:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return self.tableFooterView.frame.size.height;
}

Set detailtextlabel of static cell programmatically

I have a tableView with a few sections and I have it set for static cells instead of dynamic prototypes. The problem is that I can't set the detail text label of a static cell programmatically or at least I don't know how. Is it possible ? The only way I see of doing this is having dynamic prototypes which means I'm going to have to deal with setting up all the cell.textLabels in my dataSource and also all the sections and my segues will not work anymore. If anyone has ideas it would be great help. Thanks :)
Assuming that your UITableView is in a UITableViewController, here are 2 approaches that are useful:
Custom UITableViewCell: In the view controller class, declare a property for a label as: #property (strong) IBOutlet UILabel *labelInCell;
In the storyboard, drag a UILabel into the cell, select the controller's Connections Inspector, and connect the outlet of the property by dragging from the inspector to the UILabel object.
You can then assign the label text programmatically, for example, in viewDidLoad: of the controller class.
Standard datasource: Alternatively, you can implement just one method: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath in the view controller's datasource and set the detailTextLabel property there.

Adding UISearchBar into tableView header as subview

I'm trying to add a custom header to UITableView, that has some buttons and an UISearchBar.
The problem is, that when I try to use searchBar I get a message:
setting the first responder view of the table but we don't know its type (cell/header/footer)
Has anyone encounter such problem?
Are you adding to the table via:
[self.tableView addSubview:customView]
If so, that could be your error. Adding subviews to UITableView requires that you add them either as header, footer, or cell explicitly. Try:
self.tableView.tableHeaderView = customView
Just follow the simple steps here..
create a property for mySearchBar in your '.h' file and synthesize.
set its attributes in viewDidLoad/viewDidAppear method (or u can simply do it in the Interface Builder)
Use the following delegate method to set it as the header of your table view...
– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.mySearchBar;
}

Expandable custom- UITableViewCell from NIB

I need to create expandable-cell form nib. It looks fine if dimenssions of cell in my tableview are equal to the dimensions of custom-cell nib. But when i'm trying to change height of custom cell to make it smaller it looks like this:
Can you give me some advices how can i make expand/collapse custom table cell from nib and avoid this effect?
UPD: I have heightForRowAtIndexPath implemented and it works fine. The base problem that all outlets that should be visible only when the cell is expanded are visible over all tableview for all cells when there are collapsed
I found the solution and it's very simple. I just need to set "Clip SubViews" property of my custom-cell in the Interface Builder.
Look at the heightForRowAtIndexPath datasourse method. It can be looking like this:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (expandableCell)
return 20.0f;
return 44.0f;
}

Resources