我將UITableview與NSMutableArray綁定DataSource.I想要在用戶選擇tableview.I時獲取選定的NSMutableArray對象獲取對象但我無法訪問對象屬性和應用程序我訪問對象的屬性。我在didSelectRowAtIndexPath方法上嘗試它。這裏是我的編碼。UItableview數據源對象列表中超出範圍的對象
-(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]
了以下鏈接解決我的問題[http://stackoverflow.com/questions/5761518/variable-is-not-a-cfstring-error] [1] [1]:HTTP ://stackoverflow.com/questions/5761518/variable-is-not-a-cfstring-error –