When i click the tableview i want to send the currentbook details to another viewcontroller "detailpage" and here its not sending any value?? why also it shows error?
error : unknown receiver "tableview"
Why are you creating two GMMDetailPage Objects? Also, you should most likely have self.tableView instead of just tableView. It would also be better to pass the tableView into the prepareForSegues:sender: method like so:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:#"bookItem" sender:tableView];
}
Related
I have a problem where my table view does not show the delete button on cell swipes.
I created a separate datasource class that conforms to the UITableViewDataSource protocol. I have a UITableViewController that I am presenting using a UIPopoverPresentationController. Before presenting it, of course, I set up the datasource with all the information it needs and I ensure that it implements:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
In my UITableViewController subclass, I also am sure to implement both:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// do something (this doesn't get hit yet anyway, as delete button does not appear)
}
}
The problem seems to be that the method tableView:editingStyleForRowAtIndexPath: does not ever get called. However, if I bypass my separate datasource class and simply implement the datasource within my UITableViewController subclass, I notice that this method does get called.
I would prefer to figure out why it is the case that my using a separate datasource class gives me problems for swipe-to-delete, rather than abandoning this class (which I am using throughout my app in non-editable table views) and instead opting for keeping the datasource within the UITableViewController subclass entirely. Any pointers on where to look would be greatly appreciated!
You need to add the following tableView datasource method in your .m file.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
I have just added a UITableView in to my storyboard and the suggested constraints to it like that.. Now i have written very simple code with some delegate and datasource methods implemented like this. . Now when i tap the first row it detects nothing and check the console in the below image, when i press the second row it tells me that the indexPath.row is 0.. can some body point out that what i am doing wrong here.
You are calling -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath which is called when you deselect row , instead call
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
It's because you are using didDeSelectRowAtIndexPath: instead of didSelectRowAtIndexPath: method.
You have to call "didSelectRowAtIndexPath" Delegate method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method only return which row we have selected.
I received a memory error while working on a project with Table View.
I replicated the storyboard on a new project and received the same error.
Here's the storyboard layout:
01 - The Storyboard
If the "Back" button is pressed while the Delete button is shown then I get a memory error as below:
02 - Running app and Memory error
The code used for deletion is:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Remove the row from data model
[tableData removeObjectAtIndex:indexPath.row];
// Request table view to reload
[tableView reloadData];
}
I'm posting this question in order to learn more about Xcode and Objective-C.
Has anyone experienced something similar?
What process should I follow to debug this error?
Is there a Apple procedure to report this kind of errors?
This appears to be a bug. Using Instruments, I found that a _canEditRowAtIndexPath: message is being sent to a deallocated instance of CDUTableViewController (after it gets popped off the stack by hitting the back button). This message is never sent when the table is in a UITableViewController instead of a UIViewController -- I have no idea why that would be.
You can get around the problem by either using a UITableViewController, or by creating a strong property for the CDUTableViewController in the CDUViewController, and pushing in code rather than using a segue (that way your CDUTableViewController isn't deallocated on the pop).
Remove this line: [tableView reloadData]; - its implied.
And in the future you don't need to post a screenshot of Xcode just give us the error.
Please do the following. Use a modern property for your ivar, remove the declaration in curly braces in the implementation, and refer to that property as self.tableData everywhere in the class. See comments within:
// 1) add a private interface
#interface CDUTableViewController ()
#property(strong, nonatomic) NSMutableArray *tableData;
#end
#implementation CDUTableViewController
// 2) delete the declaration in braces here
- (void)viewDidLoad
{
[super viewDidLoad];
// 3) refer to self.tableData everywhere in this class
self.tableData = [NSMutableArray arrayWithObjects:#"Egg Benedict", // ...
}
The big fix comes at the time of delete. Update your table to match your model after the delete. Do this only for the delete editing style:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.tableData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
I have a method constructed like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//some table related stuff
}
However I cannot call this, so I basically copied and pasted the whole function and renamed as:
- (void)jumpCountry: (NSIndexPath *)indexPath {
//some table related stuff
}
and calling this method by using:
[self jumpCountry:countryIndex];
However my class looks ugly (and not preferred) because it has got the same two methods. So, how can I call the initial method directly(I know that it is assigned to a button which invokes that method). I am using iOS6.1. Basically, the reason why I want to directly call is I have another thread that listens notifications(from location services), once a notification is received, the table view should be changed. The notification itself already searches for NSIndexPath, so there won't be any problem with that.
You can just put
[self jumpCountry:countryIndex];
to your method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method a delegate method of table view from UITableViewDelegate protocol and it gets call when user select a row in UITableView. you should not call this method by your self.
instead of you can create your method and do whatever you want to do and call it in viewDidLoad or any method.
To call programatically use
[tabelView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
Here scrollIndexPath is the indexpath of row to be selected
For creating indexpath
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
This is what I am trying to do...but not sure how to do :
I have a tableview consisting of multiple rows in multiple sections. When I scroll the table going from 1 section to another, I want to do some other action - I want to have an action handler for this. But, I am not sure how to do it.
Cany anyone please help me out ? Thanks.
You can set the tableview delegate as the controller and implement this delegate function
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
This function will get called before a cell is going to be displayed. You can use the indexpath to check if it is going to be first item in a section.
Hope this helps.