Is it possible to determine a row's detailTextLabel based on an indexPath in didSelectRowAtIndexPath?
I want to be able to open a phone link using
[[UIApplication sharedApplication] openURL:xyz]
if the cell has the detail text label "phone".
Is this possible?
Thanks
[[myTableView cellForRowAtIndexPath:path].detailTextLabel.text isEqualToString:#"phone"];
Assuming that you provide the data source for the table view, you could check your data directly instead of the table view cell.
If this is somehow not possible, you could always call yourself:
[[tableView dataSource] tableView:tableView cellForRowAtIndexPath:indexPath]; and inspect the resulting cell.
Related
Im working on tableview single multiple checkbox functionality. I have done the Multiple checkbox in tableview. But i have no idea about the single selection checkbox in tableview. can anyone help me.
Thanks in advance.
Keep in a variable the current selected choice.
On tableView:cellForRowAtIndexPath: display checked image if the current indexPath.row is equal to this variable, otherwise display the image for unchecked.
Then, in tableView:didSelectRowAtIndexPath: - store the new selected cell in this variable and do a [tableview reloadData].
Use allowsMultipleSelection property of UITableView.
For Single selection
self.tableView.allowsMultipleSelection = NO;
For Multiple selection
self.tableView.allowsMultipleSelection = YES;
When my app displays the table, sometimes, it displays ALL the content of the database. but when i try to segue to another VC an return from that VC (Lets say, I added a new entry to the Database), it displays this. if you touch below the "Missing" cells, it segue to the correct entry though...
I've already tried using:
[self.cTableView setNeedsDisplay];
[self.cTableView setNeedsLayout];
or
[self.cTableView beginUpdates];
[self.cTableView endUpdates];
or
[self.cTableView reloadData];
but still to no avail. Is there any way of refreshing the tableview graphically?
I can't post images due to reputations but the image that I'm going to post looks like the TableView gets CUT going down.
Image:
https://dl.dropboxusercontent.com/u/1336061/StackOverflow/Untitled.jpg
Are you re-using your cell correctly?
Check the cells reuse identifier. see that the cells are not being allocated every iteration (in cellForRow delegate).
If the objects that provide data to the "Data Source" of the table change, you might as well need to call:
[table reloadData];
OR
Load the new elements with their indexes (look at the UITableView headers to use the right delegate.
I have a project utilizing storyboards that uses UITableView in tandem with a Navigation Controller. Its layout is similar to apple's iOS Address Book where there is a table of objects, and clicking on a cell pushes a view onto the navcontroller with that objects's details (properties). I am having trouble using the prepareForSegue method in harmony with the table view's didSelectRowAtIndex. I need a way for the prepareForSegue to know about the row passed in didSelectRowAtIndex so i can pass it's properties to the detail view controller being pushed since prepareForSegue gets called before didSelectRowAtIndex does. If possible I would still like to use the storyboard segue but if there isn't a way i can progamatically push/pop. There is another question similar to this on stackoverflow but it never really was answered, it kind of just rambled on.
If you know a work-around please let me know, thank you!
You can not use didSelectRowAtIndexPath: at all. You can get the index path in prepareForSegue: like this:
UITableViewCell *cell = (UITableViewCell*) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
Bit of background of the app I'm currently writing. It's a tableview and when a cell is tapped it loads a local HTML page.
However, now I'd like to implement section headers, a section header for complete and incomplete. The default header would be incomplete and after an interaction on the table view by a user, the cell is moved to complete. An option would be required to reverse the change should the change be done by mistake.
My first thought was to put in a check box in each cell, checking the box would move the cell and unchecking would move it back but I see iOS offers no such function, instead using switches instead.
For my needs, switches wouldn't work very well. So I'd like to ask others thoughts on this and how to implement such a thing, if anything.
Any thoughts or help appreciated.
Thanks.
You can implement a check mark using this approach. Basically you need to add a button on the cell and change its background image to show selected and deselected state. You can also consider using the default accessory check mark feature in tableview cell.
For eg:-
cell.accessoryType = UITableViewCellAccessoryCheckmark;
and
cell.accessoryType = UITableViewCellAccessoryNone;
In order to implement the section header, you can use - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section method or viewForHeaderInSection: method.
You can move a cell from one section to another one using the below method,
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath
I'm trying to do something very simple: set up a segue so that when you click on a cell in a table it will take you to another View Controller. The problem, I believe, originates from the fact that the TableView these cells are in is embedded in a regular ViewController (as opposed to a TableViewController), and is one of two subviews in this ViewController.
As far as I can tell, I've set everything up correctly: I embedded the ViewController with the two subviews in a Navigation Contoller, set it to be the dataSource and delegate for the TableView, and created a push segue from a TableViewCell to my second View Controller in the storyboard. However, when the app is run and a user clicks a row in the table, it merely selects the row and the segue doesn't fire at all (I've debugged it and the prepareForSegue function isn't even being called).
Is there something I'm missing here? Or is this for some reason not possible if the TableView is not the only view in its view controller?
I find that if I had recently wired the segue from the cell's accessory view, and later delete the segue and try to wire a new segue to the cell directly it does not work (using Xcode 4.6.2) -- Xcode keeps connecting the segue to the accessory view (even if there isn't one)! The way I fixed it is by selecting the cell in IB and using the connection inspector to (1) delete the original "accessory action" segue and (2) directly wire the "selection" segue by dragging from the filled circle in the image below to the appropriate destination view controller.
This may or may not help you, but I ran into this issue because I had defined two different cell types, and had provided didSelectRowAtIndexPath implementation. I had to add [self performSegueWithIdentifier:#"Whatever" sender:self] as part of didSelectRowAtIndexPath and the issue got resolved.
If you are able to at least detect row selections, you may be able to take advantage of this method.
If you have customized the cell rendering, e.g.:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
then ensure you are using the same cell identifier as specified for the prototype cell in ste story.
So in this case the 'Identifier' of the cell which hooked up the segue should be set to 'Cell'.
If you are creating the StoryBoard in Xcode then do the following:
Create a UITableViewController
Add a prototype UITableViewCell
Create the UIViewController that will be your segue target.
Control-Click on the prototype UITableViewCell and drag to the segue target.
That's it. You'll probably want to edit the characteristics of the UITableViewCell to be, for example, your subclass of UITableViewCell.
I had the similar issue.
Fix is
1. Write SegueIdentifier for the segue in Storyboard
2. Add the following line [self performSegueWithIdentifier:#"SegueIdentifier" sender:nil]; in didSelectRowAtIndexPath.
I hope this would help.
Had the same problem. Segue from a prototype table view cell inside a regular View Controller would make the app crash. In case someone have the same problem.
My solution:
If you are using a push segue make sure your first View Controller with the table view is embedded in a Navigation Controller otherwise "push segues" wont work. Also point the segue at the destination View Controller, not its Navigation Controller!
And as mentioned earlier, make sure your "segue identifiers" are correct.
at "didSelectRowAtIndexPath" I call "[self performSegueWithIdentifier:#"Your_destination_View_Controller" sender:self];