0

I bind the UITableview with NSMutableArray DataSource.I want to get selected NSMutableArray object when user select on tableview.I got the object but I can't access object properties and application quite if I access object's properties. I try it on didSelectRowAtIndexPath method.Here is my coding.

-(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.[http://stackoverflow.com/questions/5761518/variable-is-not-a-cfstring-error][1]
Phoenix Kyaw
  • 332
  • 1
  • 5
  • 17
  • It the following link solves my problem.[http://stackoverflow.com/questions/5761518/variable-is-not-a-cfstring-error][1] [1]: http://stackoverflow.com/questions/5761518/variable-is-not-a-cfstring-error – Phoenix Kyaw Oct 14 '11 at 09:56

2 Answers2

0

There are multiple things you have to check if an object is out of bounds in a uitableview.

1: Check if the numbersOfRowsInSection is done properly.

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

Since you haven't posted this part I assume you set this the right way.

2: You are removing objects without updating the table properly so the table is showing old data.

[self.myTableView reloadData];

This should update the UITableview data to the most recent data, and it should be done when you change your datasource array.

Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69
  • still problem.When I access object's properties,application quite, – Phoenix Kyaw Oct 14 '11 at 08:25
  • Well if it isn't the array that is bugging you it can only be the existance of the object you are trying to access. Does it exist the moment you access it? Does the data in the object exist the moment you access it, have you set those values properly? – Totumus Maximus Oct 14 '11 at 08:29
  • I access object's properties in didSelectRowAtIndexPath method.When I select the row,application quite. – Phoenix Kyaw Oct 14 '11 at 08:53
0
Try this one : DoctorItem *physician= (DoctorItem *)[[tableDataList objectAtIndex:indexPath.row] copy];
and access property with : [physician DName]
Sudesh Kumar
  • 569
  • 3
  • 13