English 中文(简体)
长时间内多处可调用的电文
原标题:Multiple checking in a long sectioned UITableView

I am running into a crazy problem when dealing with the UITableView, do you have any good sample projects (github) or tutorials that show how to do a multiple selections(checking) on a sectioned UITableView, i mean a long UITableView where the user can scroll up and down it and select/deselect the cells in different sections. The problem i ran is concerning checking cells in different sections, and scrolling up and down the table view. The app crashes, and in a better case, i get random cells checked when i scroll down and up the screen (the table view). So i decided to make a simple project in which i try all that before integrating it into my app.

One of the suit of actions that give rise to the crash is: check cell1 in section1 and check cell2 in section2, then uncheck cell1 in section1. The sample is here, please test it, it s too lightweight, tracking the crash with breakpoint, i found that this method is causing the issue:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSDictionary *dict = [self.tableData objectAtIndex:[self tableIndexFromIndexPath:indexPath]];//this statement is the issue, i think the app is conflicting between sections when check/uncheck cells
    BOOL newState = ![[dict objectForKey:kCellStateKey] boolValue];
    NSDictionary *newDict = [NSDictionary dictionaryWithObjectsAndKeys:[dict objectForKey:kCellTextKey], kCellTextKey, [NSNumber numberWithBool:newState], kCellStateKey, nil];
    [self.tableData replaceObjectAtIndex:indexPath.row withObject:newDict];

    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}

I really need your expertise to improve my code. Thanx in advance.

最佳回答

即便分配得正确,这个表格也不希望以某种理由取代信息和通信技术。

(1) 将所有假点改为可变的碎片

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSMutableDictionary *dict = [self.tableData objectAtIndex : [self tableIndexFromIndexPath : indexPath]];

    BOOL newState = ![[dict objectForKey:kCellStateKey] boolValue];

    [dict setValue :[NSNumber numberWithBool:newState] forKey : kCellStateKey];

    NSArray *test = [[NSArray alloc]initWithArray : [NSArray arrayWithObject:indexPath] ];

    [tableView reloadRowsAtIndexPaths : test withRowAnimation:UITableViewRowAnimationNone];
}
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签