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
}
}
Related
I have a table view and don't know how to access the row number when the user presses one of the cells. The data of the table view is a small array and this is the closest I could come... In the IB, I control dragged the reusable cell to the view controller I push which works fine. I am unsure how to get the row number in a conditional like this...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// A bunch of stuff is before this, but not important to the question
//-- > This line if([indexPath row] == 1) This doesn't work... any ideas?
{
if(totalPoints < 10 && number != 0)
{
[self saveNumber:#"1"];
}
else if (totalPoints < 10 && attachment == 0)
{
[self saveData:#"1"];
int newPnts = totalPoints + 1;
[self savePoints:[NSString stringWithFormat: #"%d", newPnts]];
}
Thanks
It should work
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"%#",indexPath.row);
if(indexPath.row==1)
{
NSLog(#"Do Somthing..");
}
else
{
NSLog(#"Do Somthing..");
}
}
the row number is [indexPath row] . in tableview you have a dataSource which save the data array used to reload table
Ok I was doing something wrong elsewhere and the view controller doesn't update it's label from the saved data. I will post a seperate question if you're interested
I have a UITableViewController with static cells, with 3 sections, and a segmented control with 2 buttons.
I would like to achieve the following behavior:
when button 1 is pressed hide section 2
when button 2 is pressed hied section 3
I cannot find a solution to this.
Any tip is useful.
Thanks.
Simple, just make sure you set your UITableViewDelegate, and you can use heightForRowAtIndexPath: (and similar for headers and footers) to show/hide the cells by setting their height to 0.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 2) {
if (self.shouldShowSection2) {
return 44.0f;
}else{
return 0.0f;
}
}else if (indexPath.section == 3) {
if (self.shouldShowSection3) {
return 44.0f;
}else{
return 0.0f;
}
}else{
return 44.0f;
}
}
Then just define some logic within your IBAction to change these BOOLs around in between tableview's begin/end updates, and the table will show/hide the sections you want.
- (IBAction)toggleSegment:(UISegmentedControl *)sender
{
[self.tableView beginUpdates];
// change boolean conditions for what to show/hide
[self.tableView endUpdates];
}
Can anyone advise me on how I can add a "plus" button in a UITableView Cell like what you see in the screen shot below?
You can also put the table view into editing mode, implement editingStyleForRowAtIndexPath: and return UITableViewCellEditingStyleInsert (which puts a green circle with a plus sign).
For example...
- (IBAction)editButtonPressed
{
//toggle editing on/off...
[tableView setEditing:(!tableView.editing) animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
return UITableViewCellEditingStyleInsert;
//gives green circle with +
else
return UITableViewCellEditingStyleDelete;
//or UITableViewCellEditingStyleNone
}
When the green button is pressed, the table view will call tableView:commitEditingStyle:forRowAtIndexPath::
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleInsert)
{
//handle insert...
}
else
{
//handle delete...
}
}
The simple way: get an image of the plus, set it for the cell.imageView.image.
You can customize your cell by getting the contentView property of your UITableViewCell and adding the UIImage of the plus button as a subview.
That's not a built-in control. It's probably a custom-style UIButton with that image in its .image property.
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");
}
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;
}