UITableView cell's height - objective-c

I have a simple question, not able to sort it out. I have a UITableView in my application. There are 3 section and each section has 3 rows.
I want to increase the height of first cell of the first section. I am using the delegate for this but it increases the height of the first cell of the third section.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 && sectionValue==0)
{
sectionValue=1;
return 180.0;
}
else
{
return 44.0;
}
}

You can directly use indexPath.section -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 && indexPath.section==0)
{
return 180.0;
}
else
{
return 44.0;
}
}

try this......
indexPath.section

Related

heightForRowAtIndexPath Change height variable to cell

I have three different custom cells of different heights. How should I use,
heightForRowAtIndexPath
To set the specific cell's height up. Something allong the lines of this.
if ([CellIdentifier isEqualToString:#"Cell"]) {
return 200;}
No avail
copy the code that figures out what cell to use from cellForRowAtIndexPath: to heightForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cel;
NSString *CellIdentifier;
// whatever code you use to figure out what cell to use
if ([CellIdentifier isEqualToString:#"Cell"]) {
// create & configure "Cell"-cell
}
else {
// configure Standard cell
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier;
// whatever code you use to figure out what cell to use
if ([CellIdentifier isEqualToString:#"Cell"]) {
return 200.0f;
}
else {
return 44.0f;
}
}

Changing in Code Specific Row Heights in Objective-C

I have a UITableView that uses prototype cells to recreate a table. I have the first row with height 30 and the rest default 44. I would like to change only first row's height but have failed to do so. I tried cellForRowAtIndexPath but I learned here that it's heightForRowAtIndexPath: I'm interested in. However, all the IndexPath's that get sent to it are [0,0]. Can anyone help?
Have you tried this?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { //first row
return 30;
}
else {
return 44;
}
}
Do this for resizing the cells in your table views delegate.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
return 30.0;
return 44.0;
}
If this doesn't work: give us your code

Logging a particular row in didSelectRowAtIndexPath

In the method for
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// do stuff here
}
I have a grouped table view. If I wanted Row 1 of Section 1 to spit out an NSLog, how would I do that? Also, would it be different if I wanted Row 2 of Section 3 to make a log? So far, I've only been using this method to transition between nibs.
Dirt simple:
if(indexPath.row == 1 && indexPath.section == 1) {
NSLog(#"Awesomeness");
} else if(indexPath.row == 2 && indexPath.section == 3) {
NSLog(#"Something more awesome");
}

Question about UITableView

I have a UiTableView and the first cell is only showing information. The following cells are going to push new viewControllers to the window.
I don't want it to be possible to click on the first one, but the second cell (indexpath.row == 1) to be the first cell to click on...
Is there some property I can set to make that first cell "notChooseable"?
try:
if(indexPath.row == 0)
cell.userInteractionEnabled = NO;
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return;
}
else {
//perform pushing controllers
}
}

UITableViewCell prevent deletion

I am looking for a way of preventing the deleting of one of my cells. (No delete button should appear next to the cell when the table view is in editing mode.)
How can this be made possible?
Implement editingStyleForRowAtIndexPath and return UITableViewCellEditingStyleNone for that row:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == sss && indexPath.row == rrr)
return UITableViewCellEditingStyleNone;
else
return UITableViewCellEditingStyleDelete;
}
The accepted response works but is not the correct way to do it. There are two methods available: editingStyleForRowAtIndexPath and canEditRowAtIndexPath
editingStyleForRowAtIndexPath: Use when there are multiple different editing styles in the table
canEditRowAtIndexPath: Use when some rows should edit and some should not.
Therefore the correct way to implement your table delegate is:
- (BOOL)tableView:(UITableView *)tableView
canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == sss && indexPath.row == rrr)
{
return NO;
}
return YES;
}