这段代码有什么错误导致它崩溃?
我正在使用表格视图,其中按自定义单元格显示 10 行表格,其中一行按普通单元格显示。我已经使用了这段代码...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (indexPath.row == [listofBusiness count]) {
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text= @"Show more...";
//cell = self.tvcell;
return cell;
}
else if(indexPath.row==[appDelegate.busines_Aray count])
{
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
if(customCell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"Place_cell" owner:self options:nil];
}
// Configure the cell...
cell.backgroundColor=[UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
BusinessData *business_datas = [appDelegate.busines_Aray objectAtIndex:indexPath.row];
UITextField *tmptxt;
tmptxt = (UITextField *)[cell viewWithTag:1];
tmptxt.backgroundColor=[UIColor clearColor];
tmptxt.text = [NSString stringWithFormat:@"%@",business_datas.name_business ];
tmptxt = (UITextField *)[cell viewWithTag:2];
tmptxt.text = [NSString stringWithFormat:@"%@", business_datas.cat_business];
tmptxt = (UITextField *)[cell viewWithTag:3];
tmptxt.backgroundColor=[UIColor clearColor];
tmptxt.text = [NSString stringWithFormat:@"%d",business_datas.noofreview];
if(business_datas.avg_rating ==0.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5 ,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==0.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==1.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==1.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==2.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==2.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==3.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5 ,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==3.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==4.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==4.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else //if(business_datas.avg_rating ==5.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5 ,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
return cell;
}
当编译器出现该代码时,会给出以下错误...
2011-09-13 12:24:13.641 Yelp-OnTheWay[8739:207] * -[UITableView _createPreparedCellForGlobalRow:withIndexPath:]、/SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView 中断言失败。米:5613 2011-09-13 12:24:13.643 Yelp-OnTheWay[8739:207] 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView dataSource 必须返回一个tableView 中的单元格:cellForRowAtIndexPath:' ** 第一次抛出时调用堆栈: ( 0 CoreFoundation 0x012bebe9 异常预处理 + 185 1 libobjc.A.dylib 0x014135c2 objc_异常_抛出 + 47 2 CoreFoundation 0x01277628 +[NSException 引发:格式:参数:] + 136 3 基础 0x0016747b -[NSAssertionHandler handleFailureInMethod:对象:文件:行号:描述:] + 116 4 UIKit 0x003e08f3 - [UITableView(UITableViewInternal)_createPreparedCellForGlobalRow:withIndexPath:] + 883 5 UIKit 0x003d677f - [UITableView(UITableViewInternal)_createPreparedCellForGlobalRow:] + 75 6 UIKit 0x003eb450 - [UITableView(_UITableViewPrivate)_updateVisibleCellsNow:] + 1561 7 UIKit 0x003e3538 - [UITableView布局子视图] + 242 8 QuartzCore 0x00fca451 -[CALayer 布局子层] + 181 9 QuartzCore 0x00fca17c CALayerLayoutIfNeeded + 220 10 QuartzCore 0x00fc337c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 11 QuartzCore 0x00fc30d0 _ZN2CA11Transaction6commitEv + 292 12 QuartzCore 0x00ff37d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 13 CoreFoundation 0x0129ffbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27 14 核心基础 0x012350e7 __CFRunLoopDoObservers + 295 15 核心基础 0x011fdbd7 __CFRunLoopRun + 1575 16 核心基础 0x011fd240 CFRunLoopRunSpecific + 208 17 核心基础 0x011fd161 CFRunLoopRunInMode + 97 18 图形服务 0x01b60268 GSEventRunModal + 217 19 图形服务 0x01b6032d GSEventRun + 115 20 UIKit 0x0037b42e UIApplicationMain + 1160 21 Yelp-OnTheWay 0x00002154 主 + 102 22 Yelp-OnTheWay 0x000020e5 开始 + 53 ) 抛出“NSException”实例后调用终止 程序收到信号:“SIGABRT”。 杀 退出
如何删除它?
提前致谢...
I am using table view in which I am showing 10 row of table by custom cell and one is by normal cell. I have use this code...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (indexPath.row == [listofBusiness count]) {
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text= @"Show more...";
//cell = self.tvcell;
return cell;
}
else if(indexPath.row==[appDelegate.busines_Aray count])
{
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
return cell;
}
if(customCell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"Place_cell" owner:self options:nil];
}
// Configure the cell...
cell.backgroundColor=[UIColor colorWithRed:0.92 green:0.92 blue:0.92 alpha:1];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
BusinessData *business_datas = [appDelegate.busines_Aray objectAtIndex:indexPath.row];
UITextField *tmptxt;
tmptxt = (UITextField *)[cell viewWithTag:1];
tmptxt.backgroundColor=[UIColor clearColor];
tmptxt.text = [NSString stringWithFormat:@"%@",business_datas.name_business ];
tmptxt = (UITextField *)[cell viewWithTag:2];
tmptxt.text = [NSString stringWithFormat:@"%@", business_datas.cat_business];
tmptxt = (UITextField *)[cell viewWithTag:3];
tmptxt.backgroundColor=[UIColor clearColor];
tmptxt.text = [NSString stringWithFormat:@"%d",business_datas.noofreview];
if(business_datas.avg_rating ==0.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5 ,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==0.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==1.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==1.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==2.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==2.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==3.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5 ,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==3.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==4.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"emStar.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else if(business_datas.avg_rating ==4.5)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"Black-Half.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
else //if(business_datas.avg_rating ==5.0)
{
CGRect myImage1 =CGRectMake(190,5,20,22);
UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:myImage1];
[imageView1 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView1];
[imageView1 release];
CGRect myImage2 =CGRectMake(210,5,20,22);
UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:myImage2];
[imageView2 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView2];
[imageView2 release];
CGRect myImage3 =CGRectMake(230,5,20,22);
UIImageView *imageView3 = [[UIImageView alloc] initWithFrame:myImage3];
[imageView3 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView3];
[imageView3 release];
CGRect myImage4 =CGRectMake(250,5,20,22);
UIImageView *imageView4 = [[UIImageView alloc] initWithFrame:myImage4];
[imageView4 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView4];
[imageView4 release];
CGRect myImage5 =CGRectMake(270,5 ,20,22);
UIImageView *imageView5 = [[UIImageView alloc] initWithFrame:myImage5];
[imageView5 setImage:[UIImage imageNamed:@"star.png"]];
[cell addSubview:imageView5];
[imageView5 release];
}
return cell;
}
When compiler come on that code then give following error...
2011-09-13 12:24:13.641 Yelp-OnTheWay[8739:207] * Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:5613
2011-09-13 12:24:13.643 Yelp-OnTheWay[8739:207] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
** Call stack at first throw:
(
0 CoreFoundation 0x012bebe9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x014135c2 objc_exception_throw + 47
2 CoreFoundation 0x01277628 +[NSException raise:format:arguments:] + 136
3 Foundation 0x0016747b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
4 UIKit 0x003e08f3 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 883
5 UIKit 0x003d677f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
6 UIKit 0x003eb450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
7 UIKit 0x003e3538 -[UITableView layoutSubviews] + 242
8 QuartzCore 0x00fca451 -[CALayer layoutSublayers] + 181
9 QuartzCore 0x00fca17c CALayerLayoutIfNeeded + 220
10 QuartzCore 0x00fc337c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
11 QuartzCore 0x00fc30d0 _ZN2CA11Transaction6commitEv + 292
12 QuartzCore 0x00ff37d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
13 CoreFoundation 0x0129ffbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27
14 CoreFoundation 0x012350e7 __CFRunLoopDoObservers + 295
15 CoreFoundation 0x011fdbd7 __CFRunLoopRun + 1575
16 CoreFoundation 0x011fd240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x011fd161 CFRunLoopRunInMode + 97
18 GraphicsServices 0x01b60268 GSEventRunModal + 217
19 GraphicsServices 0x01b6032d GSEventRun + 115
20 UIKit 0x0037b42e UIApplicationMain + 1160
21 Yelp-OnTheWay 0x00002154 main + 102
22 Yelp-OnTheWay 0x000020e5 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.
kill
quit
How remove it?
Thanks in advance...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用两种不同类型的单元格,则需要使用两个重用标识符。
目前尚不清楚
customCell
是什么,也不清楚何时将其设置为任何内容。您不应该一直实例化和添加新的图像视图。这将导致重复使用的单元格具有多个彼此重叠的图像视图。图像视图应在您首次实例化单元时添加,并在重用单元时进行配置。虽然看起来您正在使用 5 个图像视图来显示星级,但您可以使用我认为使用 unicode 星号字符的文本来实现此目的。
您的代码正在崩溃,因为您正在进入代码的
//Configure the cell...
部分,此时cell
为零,然后您将返回nil
这会导致引发异常,因为您必须返回一个UITableViewCell
对象。研究文档中的单元重用功能并应用其中的模式。这非常简单:
indexPath
确定重用标识符If you are using two separate types of cell you need to use two reuse identifiers.
It is not clear what
customCell
is or when that would ever be set to anything.You should not be instantiating and adding new image views all the time. This will result in a re-used cell having multiple image views on top of each other. The image views should be added when you first instatiate the cell and configured when you are reusing it. Though it looks like you are using 5 image views to show a star rating, you can achieve this with text I think using unicode star characters.
Your code is crashing because you are getting to the
//Configure the cell...
section of the code, at this pointcell
is nil, you are then returningnil
which is causing the exception to be raised, as you have to return aUITableViewCell
object.Study the cell reuse functions in the documentation and apply the pattern there. It is quite straightforward:
indexPath