UITableViewController not highlighting cell when it's selected - iphone

Hi
I've got simple question which I don't know how to answer.
In my app I've got UITableViewController with cells. When I select one item (cell) it's getting higlighted and in other thread I'm loading chunk of data to display to the user (after load is done new VC is pushed). When doing it with thread user still can interact with application like, going back to other NavController and I do want that to happen. What I don't want to happen is that when loading isn't complete user can select other cell in table and it get's highlted. How I can prevent that (only highlit, I'm checking if there was a previous request so I'm not putting another thread untli previous request is done).
So basicly my question is, how can you foribd user from interacting with table view controller?

Set the selectionStyle of the UITableViewCell's to UITableViewCellSelectionStyleNone.

You can use the following to check if row can be selected:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (rowSelected) {
return nil;
}
return indexPath;
}
So, you only select it if no row is selected. In your didSelectRowAtIndexPath method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
rowSelected = YES;
// call method that is going to do something and mark rowSelected = NO;
}
You can deselect the row by using
[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO animated:YES];

There is a risk that your users will be confused. A highlight is not enough. There should be very clear visual feedback that a network opperation is ongoing and that different rules apply.
either push the details view immediately after the user selected a row and show an activity indicator in there.
or give the whole table view a different look while loading data for the selected row: e.g. Show activity indicator in the selected row & hide the disclosure chevrons in all the other. While doing that, you can set the selection style to 'none'

Related

iPhone master detail app how to use detail view to change the text value displayed in the corresponding cell in the master view

I am brand new to iOS programming and am currently taking an iOS class at school. For a project that I am doing we have to write a basic master-detail application for iPhone. For my app, I am creating a simple to do list type of app. The name of each task is displayed in the master view, the name of the task can be changed in the detail view. I set up a save button that has an unwind segue delegate when pressed. When i press the button I segue back to the master view I cannot get the value of the corresponding cell to change in real time. I know that it the master view is getting the changed information back because the changed information doesn't get saved until control transfers back to the master view and it is getting saved. When I rerun the app, the new name is displayed instead of the default name.
here is the delegate for the unwind segue
- (IBAction) done:(UIStoryboardSegue *)segue
{
// index for the cell in the master view table that was changed
NSIndexPath *changeIndex = [self.tableView indexPathForSelectedRow];
[self tableView:self.tableView cellForRowAtIndexPath:changeIndex];
// place the new dictionary entry created by the detail view in the location of the
// array where the old entry was located
_taskList[changeIndex.row] = self.ChangedEntry;
// store the change in the plist file
[_taskList writeToFile:self->documentPlistPath atomically:YES];
}
which calls this function, which appears to change the text for a cell in a table but I'm not sure
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.textLabel.text = _taskList[indexPath.row][TASK_DATA_NAME];
return cell;
}
So yeah, I am just trying to figure out how to make the master view reflect changes made in the detail view without having to close the app and reopen it. Oh and I am using Xcode 5 and targeting iOS 7.
Basically, after you update your data model (_taskList) you need to refresh the table view by calling reloadData on it. This tells it to update all of the rows.

How to use a button to add an item to another view on Xcode

I've got a basic restaurant menu system for the iPad using storyboards, and I have a product view with a button to add the item to the order page, how can I get it so that when the user presses the add to order button it adds the product name to the order scene. I've thought about using a table view in the order page but I don't know if that was a good idea. Mainly I just need some help on how to get it to print the corresponding product name onto the order page when the button is pressed. Any ideas?
Thanks,
Aislinn
how can I get it so that when the user presses the add to order button it adds the product name to the order scene.
You're mixing up presentation and data, which is a bad idea. Create a representation of orders that has no view logic at all. When a button is pressed to add something to an order, the view controller should tell the class that manages orders to do so. When you need to display an order, the view controller should ask the class for the details. For more information, read up on the MVC design pattern, which Apple uses heavily.
Just add the product name to an NSMutableArray and have the tableview load the items from this array and display it to the user.
Edit:
When the user clicks the button to add the product, use [arrayName addObject:#"Product Name"]. Then, to load it in the tableview, use the tableview's delegate method - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{} to load the name into the cell. Something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identity = #"MainCell";
UITableViewCell *cell;
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identity] autorelease];
cell.textLabel.text = [arrayName objectAtIndex:indexPath.row];
return cell;
}

iPhone - Update current view before pushing new ViewController on UITableViewCell selected

I have a UITableView with a list of items. On selection of an item I'm navigating to a new view that displays the details of the selected item using:
DetailsVC *detailsView = [[DetailsVC alloc] initWithNibName:#"DetailsVC" bundle:nil];
[self.navigationController pushViewController:detailsView animated:YES];
Now, the details view is getting the data from the remote location so on slow connection it can take a few seconds. What I want to do is display an activity indicator over the selected row on selection.
The problem is the display of the added indicator gets delayed until the next view is ready to navigate to, which makes the indicator usless.
I've tried to add this indicator in those 2 events with the same effect:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Is there a way to add the indicator (or more general, modify the content of a UITableViewCell) in the moment of selection, before navigation occurs.
As a experiment I've also tried to pop up an alert view in the same two events which resulted in poping up the alert after navigation to the details view.
So it's [[DetailsVC alloc] init...] that takes a few seconds, right? This problem is that any view changes you make don't fully take effect until returning all the way back to the runloop, so even if you setup the indicator before creating your object, it too is waiting for the init to finish to make itself visible. What you need to do is defer the creation of your DetailsVC until after the indicator is setup.
I might be a simpler change to use blocks but I can't recall the details of that off the top of my head (haven't used blocks much since code I've been writing lately has had to stay compatible with 3.x). But to use performSelector is easy too, take those 2 lines you first quoted in your question and put them into its own method, such as:
- (void)pushDetailsView {
DetailsVC *detailsView = [[DetailsVC alloc] initWithNibName:#"DetailsVC" bundle:nil];
[self.navigationController pushViewController:detailsView animated:YES];
}
And where you had those lines before, setup your indicator and then do this (a delay of 0 doesn't mean to called it immediately, but rather ASAP after returning all the way out of the current call stack):
[self performSelector:#selector(pushDetailsView) withObject:nil withDelay:0]
you can call cell = [self rowForIndexPath:indexPath] in one of your functions. and then add the indicator to cells subview
You can either
add the indicator when u select row and push new view when data came
(simultaneously remove indicator at that time) or
Push new view, call web service to get corresponding cell data (in
viewDidLoad or viewWillAppear) and display indicator simultaneously
and when new data comes remove indicator

Reorder control isn't displayed on table view

I created an iOS application based on navigation-based application template, the application is backed by Core Data framework.
When clicking on Edit button, I want the rows to be reorder-able and delete-able.
When constructing cells, I added this line:
cell.showsReorderControl = YES;
And tableView:canMoveRowAtIndexPath: method returns YES.
But the reorder control isn't displayed in the row, Am I missing something?
From the UITableViewCell showsReorderControl docs:
For the reordering control to appear, you must not only set this
property but implement the UITableViewDataSource method
tableView:moveRowAtIndexPath:toIndexPath:. In addition, if the data
source implements tableView:canMoveRowAtIndexPath: to return NO, the
reordering control does not appear in that designated row.
The UITableView also has to be in editing mode, which it's not in by default. Usually you use a button or some other control to toggle between editing mode. To put the table view in editing mode (we assume you have a UITableViewController and your tableView property is properly set, if not, adjust for your environment):
// This line somewhere inside the UITableViewController will
// animate in the various editing controls and make sure they
// show up on your table.
[[self tableView] setEditing:YES animated:YES];
try this . . .you have to implement these two methods to get that reorder control in editing mode
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
}

iPhone Can't deselect a UITableViewCell

I have a RootViewController class which is inherited from UITableViewController.
When a cell is deselected by the user I want to enable/disable certain buttons on the toolbar.
How do I trap the deselect event?
-(void)tableView:(UITableView *)tableView deselectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
{
if(indexPath.row <= rowNumber)
{
[viewButtton setEnabled:NO];
[editButtton setEnabled:NO];
}
}
I tried using this method but it doesn't seem to execute at all. Any ideas how cam this be done?
I do not think there is a deselectRowAtIndexPath event, there is a method that you can call to deselect the indexPath, but looking at the SDK I do not see an event for this in the UITableViewDelegate: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html.
Could you enable/disable certain buttons on the toolbar during the didSelectRowAtIndexPath: event?
-Rog
This is in the current beta SDK only which means it could be buggy / changed / unsupported...
I did noticed that your method declaration doesn't match the SDK (at least, the version I have).
Try removing animated:(BOOL)animated; I don't think it's applicable here.
See line ~345 in UITableView.h, and/or right click on didDeselectRowAtIndexPath and "Jump to Definition", where you'll probably find how the delegate method should be defined.
That said, if your goal is simply to "enable/disable certain buttons when a cell is selected",
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;
should work just fine. This will occur after they select the cell and before it's deselected. 'deselect' has to do more with animation than user interaction. The only reason I can think you would want to use deselect is maybe the aesthetic value of ensuring your event only occurs after the select cell is no no longer highlighted.