Объект вне диапазона в списке объектов источника данных UItableview - PullRequest
0 голосов
/ 14 октября 2011

Я связываю UITableview с NSMutableArray DataSource. Я хочу получить выбранный объект NSMutableArray, когда пользователь выбирает на tableview. Я получил объект, но я не могу получить доступ к свойствам объекта и приложению совсем, если я получаю доступ к свойствам объекта.Я пытаюсь сделать это с помощью метода didSelectRowAtIndexPath. Вот мое кодирование.

-(UITableViewCell *) tableView : (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    DoctorItem *physician=(DoctorItem*)[tableDataList objectAtIndex:indexPath.row];

    UILabel *lbName=[[UILabel alloc] initWithFrame:CGRectMake(10, 10, 290, 25)];
    [lbName setText:physician.DName];
    [cell.contentView addSubview:lbName];
    [lbName release];


    UILabel *lbQualifications=[[UILabel alloc]initWithFrame:CGRectMake(10,40,290,25)];
    [lbQualifications setText:physician.Qualifications];
    lbQualifications.textColor=[UIColor lightGrayColor];

    CGSize maximumLabelSize=CGSizeMake(296,9999);
    CGSize expectedLabelSize=[physician.Qualifications sizeWithFont:lbQualifications.font 
                                                  constrainedToSize:maximumLabelSize
                                                      lineBreakMode:lbQualifications.lineBreakMode];

    CGRect newFrame=lbQualifications.frame;
    newFrame.size.height=expectedLabelSize.height;
    lbQualifications.frame=newFrame;
    [cell.contentView addSubview:lbQualifications];
    lbQualifications.numberOfLines=0;

    lbQualifications.lineBreakMode=UILineBreakModeWordWrap;
    [lbQualifications release];
    UILabel *lbCategory=[[UILabel alloc]initWithFrame:CGRectMake(10,80,290,25)];
    [lbCategory setText:physician.CName];
    lbCategory.textColor=[UIColor lightGrayColor];  [cell.contentView addSubview:lbCategory];
    [lbCategory release];
    [physician release];

    return cell;

}

-(CGFloat)tableView :(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
    return 110;
}

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{   
    DoctorItem *physician=[tableDataList objectAtIndex:indexPath.row];
    if(physician!=nil)
    {
        UIAlertView *alert=[[[UIAlertView alloc]initWithTitle:@"" message:physician.DName delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
        [alert addButtonWithTitle:@"OK"];
        [alert show];
    }

    [physician release];
}                                                                                                          It the following link solves my problem.[/6746442/peremennaya-ne-yavlyaetsya-oshibkoi-cfstring][1]

Ответы [ 2 ]

0 голосов
/ 14 октября 2011
Try this one : DoctorItem *physician= (DoctorItem *)[[tableDataList objectAtIndex:indexPath.row] copy];
and access property with : [physician DName]
0 голосов
/ 14 октября 2011

Есть несколько вещей, которые вы должны проверить, если объект выходит за пределы в uitableview.

1: Проверьте, правильно ли выполнен numbersOfRowsInSection.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.myArray.count;   
}

Поскольку у вас нетНе опубликовал эту часть, я предполагаю, что вы установили это правильно.

2: Вы удаляете объекты без надлежащего обновления таблицы, поэтому таблица показывает старые данные.

[self.myTableView reloadData];

Это должнообновите данные UITableview до самых последних данных, и это следует делать при изменении массива источника данных.

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