Iphone UItableview数据源对象列表中的对象超出范围
我将UITableview与NSMutableArray数据源绑定。我希望在用户在tableview上选择时获取选定的NSMutableArray对象。我获取了该对象,但如果访问对象的属性,则无法完全访问对象属性和应用程序。我在didSelectRowAtIndexPath方法上进行了尝试Iphone UItableview数据源对象列表中的对象超出范围,iphone,objective-c,ios,cocoa-touch,Iphone,Objective C,Ios,Cocoa Touch,我将UITableview与NSMutableArray数据源绑定。我希望在用户在tableview上选择时获取选定的NSMutableArray对象。我获取了该对象,但如果访问对象的属性,则无法完全访问对象属性和应用程序。我在didSelectRowAtIndexPath方法上进行了尝试 -(UITableViewCell *) tableView : (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexP
-(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]
如果一个对象在uitableview中超出范围,则需要检查多个事项 1:检查ROWSOF编号是否正确
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.myArray.count;
}
既然你还没有发布这个部分,我想你设置的方法是正确的
2:删除对象时未正确更新表,因此表显示旧数据
[self.myTableView reloadData];
这应该将UITableview数据更新为最新的数据,并且应该在您更改数据源数组时执行。仍然存在问题。当我访问对象的属性时,应用程序会非常好,如果不是数组在困扰您,那么它只能是您尝试访问的对象的存在。当您访问它时,它是否存在?当您访问对象时,对象中的数据是否存在,您是否正确设置了这些值?我在didSelectRowAtIndexPath方法中访问对象的属性。当我选择行时,应用程序仍然存在问题。当我访问对象的属性时,应用程序仍然存在问题。在自定义对象中检查这些变量的属性,这是didSelectRowAtIndexPath中的访问。以下链接解决了我的问题。[[1]:
Try this one : DoctorItem *physician= (DoctorItem *)[[tableDataList objectAtIndex:indexPath.row] copy];
and access property with : [physician DName]