iPhone-SDK:How to avoid Multiple Row Selection view? - iphone

I have a table and row contents(hard coded contents). when i choose one row and see the content and then come back to same table and try to choose another row, it doesn't deselect the first row selection(by default it shows Blue selection-UITableViewCellSelectionStyleBlue), instead both the rows are being in selected mode.
I was hoping, when we choose one row and then choose another row, by default it should unhighlight immediately the previous row selection.
Why and when should it happen?
I tried code 'cell.selectionStyle = UITableViewCellSelectionStyleNone;'
and tableView.allowsSelection=NO;
but no success, these are just not allowing completely from selection view.
I want when one row is selected and then the another is getting selected, the first row selection should be cleared and should show only the current row selection.
Any help please?

In your tableView:didSelectRowAtIndexPath: method or in the method you call when entering edit mode (the one containing [tableView setEditing:YES animated:YES];), add the following line:
[tableView deselectRowAtIndexPath:indexPath animated:YES];
before pushing a new controller.

Related

Display/Hide cell in table using Birt report

I Have two cell in one row.
I want to show and hide based on condition.
For cell visiblity expression option not showing this is showing only for text/label.
In the script I am adding
if(params["chk"].value == "both"){
this.getStyle().display = "none";}
Any solution please?
You cannot hide a cell. This wouldn't make sense. You can hide the content inside a cell, or you can hide whole rows or columns.

Crash while reloading row and the whole table at the same time

I have a nice bug here, specially in slow devices.
I have a UITableView jusk like the ones in the App Store app, with a Load More button at the bottom.
When it is pressed, I load the new info from the server, set the array, and reload the table view. In that info is also the url of the image for each object displayed in the table rows, so when we got it we start donwloading the image. When the image is loaded, I reload the row of the object.
[self.searchResultsTableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: path] withRowAnimation: UITableViewRowAnimationNone];
The problem comes when the row is being reloading because the image was downloaded, and the whole table is doing so cause the user pressed the load more button and more info was gotten. Then I get this error:
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (140) must be equal to the number of rows contained in that section before the update (125), plus or minus the number of rows inserted or deleted from that section (1 inserted, 1 deleted).
Which is perfectly understable, the table was enlarged while the new image row was being updated.
My question is: how can lock it so I do not reload that row until the whole table is reloaded? It would nice something like table.isReloading. I try with a boolean lock, and doing both actions in the main thread, but it did not work ...
Thanks a lot.
Well, a little research in the doc put some more light in all this.
reloadRowsAtIndexPaths:withRowAnimation: Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.
And that is what I did, I got the cell and set the new value for image, instead of reloading the whole of it. I guess it is more efficient also:
AHMyTableViewCell *cell = (AHMyTableViewCell *) [self.myTableView cellForRowAtIndexPath:path];
if ((cell != nil) && ([cell isKindOfClass:[AHMyTableViewCell class]]))
cell.myImageView.image = image;
It does not crash now.

iPhone: Cells order changes in UITableView Section After Call to reloadSections: Method

I have a table with two sections. A segmented control in first sections changes which rows are displayed in the second section. My problem is that the order of the rows and which row are displayed in the second section shifts improperly upon each subsequent press of a button in the segmented control.
I allow a user to add a product to a shopping list 3 different ways: by name, by barcord and by taking a picture with a camera. I have 3 buttons in a UISegmentedControl so the users can select which method to use. Depending on which segement the user selects the fields in the second segment should change to show cells relevant to that method.
Section 0:
0 row with segmented control showing name, barcode and camera buttons
Section 1:
// button zero, name button
0 row with textfield
1 row with textfield
or
// button 1, barcode button
0 row with textfield
or
// button 2, camera button
// shows camera view
I've put placeholders in each UITextField.
Each time a button in the segmented control is clicked, I call a pickOne: method that updates the tablevew. In that method, I construct a NSIndexSet with NSRange of (1, 1), and then I call the reloadSections: method of the UITableViewController with the NSIndexSet as a parameter.
When the view appears for the first time, everything is ok but when I click the buttons repeatedly, the order of the cells changes. Cells containing the two textFields for the button0 and the new placeHolders are written over the old ones.
Worse, sometimes when I click on button 0, it shows me only the second cell of the two cells.
My detailed code can be seen here http://pastebin.com/9GwMpCS9
I'm seeing a couple of problems.
The first big one is that you're adding subviews into the cells bypassing the contentView. Subviews in predefined styles are broken up into different parts depending on their roles. You have the editing control, the content view, and the accessory view. While you can add directly to the cell's view, there'll be odd behavior because the predefined cells are expecting the content to be in the content view.
I think what's causing your problem is that you're adding subviews every time a cell is decorated but you never remove them. When a cell is dequeued there's no guarantee that everything is restored to the pristine new condition as if it was alloc'ed. Things like custom accessory views that aren't removed can be left behind. I'm pretty sure that's happening. You're collecting visual trash on cells that should be clean.
I believe your problem is here.
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//....
if(addMode == NAME) {
if(indexPath.row == 0) {
[cell addSubview:nameTextField];
}
else if(indexPath.row == 1) {
[cell addSubview:categoryTextField];
}
}
else if(addMode == BARCODE) {
[cell addSubview:barcodeTextField];
}
else if(addMode == SCAN){
//Scanning mode
}
}
return cell;
}
This because the table always shows has having two sections, this method is always called for section 1. Regardless of the input type selected, it creates or dequeue a cell and returns it. Whenever addMode==SCAN, it randomly dequeues one of the previously used cells for the name or barcode addMode and returns that.
I suggest that you remove the SCAN logic from the table altogether or that you create a row for the camera.
I think the latter the best UI. With the first two buttons, the users is presented with a choice in the second section. You should maintain that pattern with the camera choice. Just have a cell that displays a button that evokes the camera. Yes, it adds a second step but establishes a kinetic pattern for the user: Select input type in section one then select an appropriate cell in section two. The user shouldn't have to stop and think each time whether they need to hit one of the rows in section two or not. They should just do so automatically.

value in the Table view is repeating after the 11th row

I am beginner iphone developer I want created table in programatically. In the table we take more than 20 row. But i have some problem that after 11th row the same value repeated.
plz help me with code and other method
You may want to look at this question which is the same problem. In that case, the person was setting the text of the cell only when creating a new cell (when nil was returned from [tableView dequeueReusableCellWithIdentifier:].) It needs to be set every time the tableView:cellForRowAtIndexPath: is called.
when you use reuseIdentifyer, the new cell to display is the cell that has just disappeared. so it will contain all the data from the disappeared cell. for example, if the cell, that has just disappeared, has detailDisclosureIndicator, the new cell will have it too even you don't set it.

Deletion button appearing below section index in UITableView

I have my UITableView set up (in the standard way) to allow deletion on swipes. Whenever I have a sectionindex showing, however, the "Delete" button appears /below/ the section index:
Perhaps I'm missing something obvious?
I've tried setting the selected cell to be less wide in willBeginEditingRowAtIndexPath, but this removes the seperator line below the cell too (i.e. the line is part of the cell, so doesn't draw in the area outside the cell's new bounds).
The solution we used is to remove the index when the table is in editing mode (the other option is, obviously, don't use both table features in the same table).