Неверный путь индекса для использования с UITableView при выборе строк за определенным числом - PullRequest
2 голосов
/ 02 января 2012
- (int)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:   (NSInteger)section
{
return @"Substitutes";
}

- (int)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{

int cnt=[subArray count];
return [subArray count];
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath    *)indexPath
{
NSArray *visible = [tableView indexPathsForVisibleRows];

NSIndexPath *indexpath = (NSIndexPath*)[visible objectAtIndex:0];


if ((selectedIndexPath != nil) && (selectedIndexPath.row == indexPath.row)){


    NSUInteger row = [indexPath row];

    NSString *subtitle =[[subArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSString *subDet =[[subDetArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    int height =  [self heightOfCellWithTitle:subtitle andSubtitle:subDet];
    return(height < CONST_Cell_height ? CONST_Cell_height : height);


}

return 40.0;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
static NSString *CellIdentifier = @"SearchCell";
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
if ((selectedIndexPath != nil) && (selectedIndexPath.row == indexPath.row)){
    cell = [self CreateMultilinesCell:CellIdentifier];

    cell.textLabel.text=[[subArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    cell.detailTextLabel.text =[[subDetArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    return cell;        
} else {

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

    cell.textLabel.text=[[subArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    cell.detailTextLabel.text =[[subDetArray objectAtIndex:row] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    return cell; 
 }

}

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (selectedIndexPath == indexPath) {
    selectedIndexPath = nil;
    [table reloadData];
} else {
    selectedIndexPath = indexPath;
    //static NSString *CellIdentifier = @"Cell";
    //UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    //cell.textLabel.text=@"test";
    //cell.detailTextLabel.text =@"det Test";
    [table reloadData];
}
 [self.table deselectRowAtIndexPath : indexPath animated : NO];
 [tableView beginUpdates];
 [tableView endUpdates];

}

Я реализовал табличное представление, используя приведенный выше код. При выборе строки №. 26 В или больше расширяет выбор, но не сжимается при следующем щелчке. И выдает ошибку при прокрутке

NSInternalInconsistencyException ', причина:' Неверный путь индекса для использования с UITableView. Индексные пути, передаваемые в табличное представление, должны содержать ровно два индекса, определяющих раздел и строку. Пожалуйста, используйте категорию по NSIndexPath в UITableView.h, если это возможно. '

код работает плавно для 25 строк. где я ошибся?

Ответы [ 2 ]

2 голосов
/ 30 апреля 2015

Используйте вот так

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag-1 inSection:0];

CGRect rectOfCellInTableView = [objTableView rectForRowAtIndexPath:indexPath];

CGRect rectOfCellInSuperview = [objTableView convertRect:rectOfCellInTableView toView:[objTableView superview]];
2 голосов
/ 04 января 2012

я получил это окончательно. :) selectedIndexpath выдает мусор. я заменяю его на self.selectedIndexpath. я не понимаю, почему это так на записи нет. 25 лет. Но это сработало для меня

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...